You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

qcustomplot.h 168 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018
  1. /***************************************************************************
  2. ** **
  3. ** QCustomPlot, an easy to use, modern plotting widget for Qt **
  4. ** Copyright (C) 2011-2015 Emanuel Eichhammer **
  5. ** **
  6. ** This program is free software: you can redistribute it and/or modify **
  7. ** it under the terms of the GNU General Public License as published by **
  8. ** the Free Software Foundation, either version 3 of the License, or **
  9. ** (at your option) any later version. **
  10. ** **
  11. ** This program is distributed in the hope that it will be useful, **
  12. ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
  13. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
  14. ** GNU General Public License for more details. **
  15. ** **
  16. ** You should have received a copy of the GNU General Public License **
  17. ** along with this program. If not, see http://www.gnu.org/licenses/. **
  18. ** **
  19. ****************************************************************************
  20. ** Author: Emanuel Eichhammer **
  21. ** Website/Contact: http://www.qcustomplot.com/ **
  22. ** Date: 22.12.15 **
  23. ** Version: 1.3.2 **
  24. ****************************************************************************/
  25. #ifndef QCUSTOMPLOT_H
  26. #define QCUSTOMPLOT_H
  27. #include <qmath.h>
  28. #include <QCache>
  29. #include <QDateTime>
  30. #include <QDebug>
  31. #include <QFlags>
  32. #include <QMargins>
  33. #include <QMouseEvent>
  34. #include <QMultiMap>
  35. #include <QObject>
  36. #include <QPaintEvent>
  37. #include <QPainter>
  38. #include <QPixmap>
  39. #include <QPointer>
  40. #include <QStack>
  41. #include <QString>
  42. #include <QVector2D>
  43. #include <QVector>
  44. #include <QWidget>
  45. #include <limits>
  46. /*
  47. #include<QList>
  48. #include "XxwTracer.h"
  49. */
  50. #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
  51. #include <qnumeric.h>
  52. #include <QPrintEngine>
  53. #include <QPrinter>
  54. #else
  55. #include <QtNumeric>
  56. #include <QtPrintSupport/QtPrintSupport>
  57. #endif
  58. class QCPPainter;
  59. class QCustomPlot;
  60. class QCPLayerable;
  61. class QCPLayoutElement;
  62. class QCPLayout;
  63. class QCPAxis;
  64. class QCPAxisRect;
  65. class QCPAxisPainterPrivate;
  66. class QCPAbstractPlottable;
  67. class QCPGraph;
  68. class QCPAbstractItem;
  69. class QCPItemPosition;
  70. class QCPLayer;
  71. class QCPPlotTitle;
  72. class QCPLegend;
  73. class QCPAbstractLegendItem;
  74. class QCPColorMap;
  75. class QCPColorScale;
  76. class QCPBars;
  77. /*! \file */
  78. // decl definitions for shared library compilation/usage:
  79. #if defined(QCUSTOMPLOT_COMPILE_LIBRARY)
  80. #define QCP_LIB_DECL Q_DECL_EXPORT
  81. #elif defined(QCUSTOMPLOT_USE_LIBRARY)
  82. #define QCP_LIB_DECL Q_DECL_IMPORT
  83. #else
  84. #define QCP_LIB_DECL
  85. #endif
  86. /*!
  87. The QCP Namespace contains general enums and QFlags used throughout the QCustomPlot library
  88. */
  89. namespace QCP {
  90. /*!
  91. Defines the sides of a rectangular entity to which margins can be applied.
  92. \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins
  93. */
  94. enum MarginSide {
  95. msLeft = 0x01 ///< <tt>0x01</tt> left margin
  96. ,
  97. msRight = 0x02 ///< <tt>0x02</tt> right margin
  98. ,
  99. msTop = 0x04 ///< <tt>0x04</tt> top margin
  100. ,
  101. msBottom = 0x08 ///< <tt>0x08</tt> bottom margin
  102. ,
  103. msAll = 0xFF ///< <tt>0xFF</tt> all margins
  104. ,
  105. msNone = 0x00 ///< <tt>0x00</tt> no margin
  106. };
  107. Q_DECLARE_FLAGS(MarginSides, MarginSide)
  108. /*!
  109. Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is
  110. neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective
  111. element how it is drawn. Typically it provides a \a setAntialiased function for this.
  112. \c AntialiasedElements is a flag of or-combined elements of this enum type.
  113. \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements
  114. */
  115. enum AntialiasedElement {
  116. aeAxes = 0x0001 ///< <tt>0x0001</tt> Axis base line and tick marks
  117. ,
  118. aeGrid = 0x0002 ///< <tt>0x0002</tt> Grid lines
  119. ,
  120. aeSubGrid = 0x0004 ///< <tt>0x0004</tt> Sub grid lines
  121. ,
  122. aeLegend = 0x0008 ///< <tt>0x0008</tt> Legend box
  123. ,
  124. aeLegendItems = 0x0010 ///< <tt>0x0010</tt> Legend items
  125. ,
  126. aePlottables = 0x0020 ///< <tt>0x0020</tt> Main lines of plottables (excluding error bars, see
  127. ///< element \ref aeErrorBars)
  128. ,
  129. aeItems = 0x0040 ///< <tt>0x0040</tt> Main lines of items
  130. ,
  131. aeScatters = 0x0080 ///< <tt>0x0080</tt> Scatter symbols of plottables (excluding scatter
  132. ///< symbols of type ssPixmap)
  133. ,
  134. aeErrorBars = 0x0100 ///< <tt>0x0100</tt> Error bars
  135. ,
  136. aeFills = 0x0200 ///< <tt>0x0200</tt> Borders of fills (e.g. under or between graphs)
  137. ,
  138. aeZeroLine = 0x0400 ///< <tt>0x0400</tt> Zero-lines, see \ref QCPGrid::setZeroLinePen
  139. ,
  140. aeAll = 0xFFFF ///< <tt>0xFFFF</tt> All elements
  141. ,
  142. aeNone = 0x0000 ///< <tt>0x0000</tt> No elements
  143. };
  144. Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement)
  145. /*!
  146. Defines plotting hints that control various aspects of the quality and speed of plotting.
  147. \see QCustomPlot::setPlottingHints
  148. */
  149. enum PlottingHint {
  150. phNone = 0x000 ///< <tt>0x000</tt> No hints are set
  151. ,
  152. phFastPolylines = 0x001 ///< <tt>0x001</tt> Graph/Curve lines are drawn with a faster method.
  153. ///< This reduces the quality
  154. ///< especially of the line segment joins. (Only relevant
  155. ///< for solid line pens.)
  156. ,
  157. phForceRepaint =
  158. 0x002 ///< <tt>0x002</tt> causes an immediate repaint() instead of a soft update() when
  159. ///< QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpHint.
  160. ///< This is set by default to prevent the plot from freezing on fast
  161. ///< consecutive replots (e.g. user drags ranges with mouse).
  162. ,
  163. phCacheLabels = 0x004 ///< <tt>0x004</tt> axis (tick) labels will be cached as pixmaps,
  164. ///< increasing replot performance.
  165. };
  166. Q_DECLARE_FLAGS(PlottingHints, PlottingHint)
  167. /*!
  168. Defines the mouse interactions possible with QCustomPlot.
  169. \c Interactions is a flag of or-combined elements of this enum type.
  170. \see QCustomPlot::setInteractions
  171. */
  172. enum Interaction {
  173. iRangeDrag = 0x001 ///< <tt>0x001</tt> Axis ranges are draggable (see \ref
  174. ///< QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes)
  175. ,
  176. iRangeZoom = 0x002 ///< <tt>0x002</tt> Axis ranges are zoomable with the mouse wheel (see \ref
  177. ///< QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes)
  178. ,
  179. iMultiSelect =
  180. 0x004 ///< <tt>0x004</tt> The user can select multiple objects by holding the modifier set
  181. ///< by \ref QCustomPlot::setMultiSelectModifier while clicking
  182. ,
  183. iSelectPlottables = 0x008 ///< <tt>0x008</tt> Plottables are selectable (e.g. graphs, curves,
  184. ///< bars,... see QCPAbstractPlottable)
  185. ,
  186. iSelectAxes = 0x010 ///< <tt>0x010</tt> Axes are selectable (or parts of them, see
  187. ///< QCPAxis::setSelectableParts)
  188. ,
  189. iSelectLegend = 0x020 ///< <tt>0x020</tt> Legends are selectable (or their child items, see
  190. ///< QCPLegend::setSelectableParts)
  191. ,
  192. iSelectItems = 0x040 ///< <tt>0x040</tt> Items are selectable (Rectangles, Arrows, Textitems,
  193. ///< etc. see \ref QCPAbstractItem)
  194. ,
  195. iSelectOther = 0x080 ///< <tt>0x080</tt> All other objects are selectable (e.g. your own derived
  196. ///< layerables, the plot title,...)
  197. };
  198. Q_DECLARE_FLAGS(Interactions, Interaction)
  199. /*! \internal
  200. Returns whether the specified \a value is considered an invalid data value for plottables (i.e.
  201. is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the
  202. compiler flag \c QCUSTOMPLOT_CHECK_DATA is set.
  203. */
  204. inline bool isInvalidData(double value)
  205. {
  206. return qIsNaN(value) || qIsInf(value);
  207. }
  208. /*! \internal
  209. \overload
  210. Checks two arguments instead of one.
  211. */
  212. inline bool isInvalidData(double value1, double value2)
  213. {
  214. return isInvalidData(value1) || isInvalidData(value2);
  215. }
  216. /*! \internal
  217. Sets the specified \a side of \a margins to \a value
  218. \see getMarginValue
  219. */
  220. inline void setMarginValue(QMargins& margins, QCP::MarginSide side, int value)
  221. {
  222. switch (side) {
  223. case QCP::msLeft:
  224. margins.setLeft(value);
  225. break;
  226. case QCP::msRight:
  227. margins.setRight(value);
  228. break;
  229. case QCP::msTop:
  230. margins.setTop(value);
  231. break;
  232. case QCP::msBottom:
  233. margins.setBottom(value);
  234. break;
  235. case QCP::msAll:
  236. margins = QMargins(value, value, value, value);
  237. break;
  238. default:
  239. break;
  240. }
  241. }
  242. /*! \internal
  243. Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or
  244. \ref QCP::msAll, returns 0.
  245. \see setMarginValue
  246. */
  247. inline int getMarginValue(const QMargins& margins, QCP::MarginSide side)
  248. {
  249. switch (side) {
  250. case QCP::msLeft:
  251. return margins.left();
  252. case QCP::msRight:
  253. return margins.right();
  254. case QCP::msTop:
  255. return margins.top();
  256. case QCP::msBottom:
  257. return margins.bottom();
  258. default:
  259. break;
  260. }
  261. return 0;
  262. }
  263. } // end of namespace QCP
  264. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
  265. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
  266. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides)
  267. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions)
  268. class QCP_LIB_DECL QCPScatterStyle
  269. {
  270. Q_GADGET
  271. public:
  272. /*!
  273. Defines the shape used for scatter points.
  274. On plottables/items that draw scatters, the sizes of these visualizations (with exception of
  275. \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are
  276. drawn with the pen and brush specified with \ref setPen and \ref setBrush.
  277. */
  278. Q_ENUMS(ScatterShape)
  279. enum ScatterShape {
  280. ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with
  281. ///< lines)
  282. ,
  283. ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you
  284. ///< want a round shape with a certain radius)
  285. ,
  286. ssCross ///< \enumimage{ssCross.png} a cross
  287. ,
  288. ssPlus ///< \enumimage{ssPlus.png} a plus
  289. ,
  290. ssCircle ///< \enumimage{ssCircle.png} a circle
  291. ,
  292. ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the
  293. ///< brush as with ssCircle)
  294. ,
  295. ssSquare ///< \enumimage{ssSquare.png} a square
  296. ,
  297. ssDiamond ///< \enumimage{ssDiamond.png} a diamond
  298. ,
  299. ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and
  300. ///< plus
  301. ,
  302. ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline
  303. ,
  304. ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing
  305. ///< on corner
  306. ,
  307. ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside
  308. ,
  309. ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside
  310. ,
  311. ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside
  312. ,
  313. ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside
  314. ,
  315. ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal
  316. ///< lines
  317. ,
  318. ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point
  319. ///< coordinates
  320. ,
  321. ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref
  322. ///< setCustomPath)
  323. };
  324. QCPScatterStyle();
  325. QCPScatterStyle(ScatterShape shape, double size = 6);
  326. QCPScatterStyle(ScatterShape shape, const QColor& color, double size);
  327. QCPScatterStyle(ScatterShape shape, const QColor& color, const QColor& fill, double size);
  328. QCPScatterStyle(ScatterShape shape, const QPen& pen, const QBrush& brush, double size);
  329. QCPScatterStyle(const QPixmap& pixmap);
  330. QCPScatterStyle(const QPainterPath& customPath, const QPen& pen,
  331. const QBrush& brush = Qt::NoBrush, double size = 6);
  332. // getters:
  333. double size() const
  334. {
  335. return mSize;
  336. }
  337. ScatterShape shape() const
  338. {
  339. return mShape;
  340. }
  341. QPen pen() const
  342. {
  343. return mPen;
  344. }
  345. QBrush brush() const
  346. {
  347. return mBrush;
  348. }
  349. QPixmap pixmap() const
  350. {
  351. return mPixmap;
  352. }
  353. QPainterPath customPath() const
  354. {
  355. return mCustomPath;
  356. }
  357. // setters:
  358. void setSize(double size);
  359. void setShape(ScatterShape shape);
  360. void setPen(const QPen& pen);
  361. void setBrush(const QBrush& brush);
  362. void setPixmap(const QPixmap& pixmap);
  363. void setCustomPath(const QPainterPath& customPath);
  364. // non-property methods:
  365. bool isNone() const
  366. {
  367. return mShape == ssNone;
  368. }
  369. bool isPenDefined() const
  370. {
  371. return mPenDefined;
  372. }
  373. void applyTo(QCPPainter* painter, const QPen& defaultPen) const;
  374. void drawShape(QCPPainter* painter, QPointF pos) const;
  375. void drawShape(QCPPainter* painter, double x, double y) const;
  376. protected:
  377. // property members:
  378. double mSize;
  379. ScatterShape mShape;
  380. QPen mPen;
  381. QBrush mBrush;
  382. QPixmap mPixmap;
  383. QPainterPath mCustomPath;
  384. // non-property members:
  385. bool mPenDefined;
  386. };
  387. Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE);
  388. class QCP_LIB_DECL QCPPainter : public QPainter
  389. {
  390. Q_GADGET
  391. public:
  392. /*!
  393. Defines special modes the painter can operate in. They disable or enable certain subsets of
  394. features/fixes/workarounds, depending on whether they are wanted on the respective output
  395. device.
  396. */
  397. enum PainterMode {
  398. pmDefault = 0x00 ///< <tt>0x00</tt> Default mode for painting on screen devices
  399. ,
  400. pmVectorized = 0x01 ///< <tt>0x01</tt> Mode for vectorized painting (e.g. PDF export). For
  401. ///< example, this prevents some antialiasing fixes.
  402. ,
  403. pmNoCaching = 0x02 ///< <tt>0x02</tt> Mode for all sorts of exports (e.g. PNG, PDF,...). For
  404. ///< example, this prevents using cached pixmap labels
  405. ,
  406. pmNonCosmetic = 0x04 ///< <tt>0x04</tt> Turns pen widths 0 to 1, i.e. disables cosmetic
  407. ///< pens. (A cosmetic pen is always drawn with width 1 pixel in the
  408. ///< vector image/pdf viewer, independent of zoom.)
  409. };
  410. Q_FLAGS(PainterMode PainterModes)
  411. Q_DECLARE_FLAGS(PainterModes, PainterMode)
  412. QCPPainter();
  413. QCPPainter(QPaintDevice* device);
  414. ~QCPPainter();
  415. // getters:
  416. bool antialiasing() const
  417. {
  418. return testRenderHint(QPainter::Antialiasing);
  419. }
  420. PainterModes modes() const
  421. {
  422. return mModes;
  423. }
  424. // setters:
  425. void setAntialiasing(bool enabled);
  426. void setMode(PainterMode mode, bool enabled = true);
  427. void setModes(PainterModes modes);
  428. // methods hiding non-virtual base class functions (QPainter bug workarounds):
  429. bool begin(QPaintDevice* device);
  430. void setPen(const QPen& pen);
  431. void setPen(const QColor& color);
  432. void setPen(Qt::PenStyle penStyle);
  433. void drawLine(const QLineF& line);
  434. void drawLine(const QPointF& p1, const QPointF& p2)
  435. {
  436. drawLine(QLineF(p1, p2));
  437. }
  438. void save();
  439. void restore();
  440. // non-virtual methods:
  441. void makeNonCosmetic();
  442. protected:
  443. // property members:
  444. PainterModes mModes;
  445. bool mIsAntialiasing;
  446. // non-property members:
  447. QStack<bool> mAntialiasingStack;
  448. };
  449. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes)
  450. class QCP_LIB_DECL QCPLayer : public QObject
  451. {
  452. Q_OBJECT
  453. /// \cond INCLUDE_QPROPERTIES
  454. Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
  455. Q_PROPERTY(QString name READ name)
  456. Q_PROPERTY(int index READ index)
  457. Q_PROPERTY(QList<QCPLayerable*> children READ children)
  458. Q_PROPERTY(bool visible READ visible WRITE setVisible)
  459. /// \endcond
  460. public:
  461. QCPLayer(QCustomPlot* parentPlot, const QString& layerName);
  462. ~QCPLayer();
  463. // getters:
  464. QCustomPlot* parentPlot() const
  465. {
  466. return mParentPlot;
  467. }
  468. QString name() const
  469. {
  470. return mName;
  471. }
  472. int index() const
  473. {
  474. return mIndex;
  475. }
  476. QList<QCPLayerable*> children() const
  477. {
  478. return mChildren;
  479. }
  480. bool visible() const
  481. {
  482. return mVisible;
  483. }
  484. // setters:
  485. void setVisible(bool visible);
  486. protected:
  487. // property members:
  488. QCustomPlot* mParentPlot;
  489. QString mName;
  490. int mIndex;
  491. QList<QCPLayerable*> mChildren;
  492. bool mVisible;
  493. // non-virtual methods:
  494. void addChild(QCPLayerable* layerable, bool prepend);
  495. void removeChild(QCPLayerable* layerable);
  496. private:
  497. Q_DISABLE_COPY(QCPLayer)
  498. friend class QCustomPlot;
  499. friend class QCPLayerable;
  500. };
  501. class QCP_LIB_DECL QCPLayerable : public QObject
  502. {
  503. Q_OBJECT
  504. /// \cond INCLUDE_QPROPERTIES
  505. Q_PROPERTY(bool visible READ visible WRITE setVisible)
  506. Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
  507. Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable)
  508. Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged)
  509. Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased)
  510. /// \endcond
  511. public:
  512. QCPLayerable(QCustomPlot* plot, QString targetLayer = QString(),
  513. QCPLayerable* parentLayerable = 0);
  514. ~QCPLayerable();
  515. // getters:
  516. bool visible() const
  517. {
  518. return mVisible;
  519. }
  520. QCustomPlot* parentPlot() const
  521. {
  522. return mParentPlot;
  523. }
  524. QCPLayerable* parentLayerable() const
  525. {
  526. return mParentLayerable.data();
  527. }
  528. QCPLayer* layer() const
  529. {
  530. return mLayer;
  531. }
  532. bool antialiased() const
  533. {
  534. return mAntialiased;
  535. }
  536. // setters:
  537. void setVisible(bool on);
  538. Q_SLOT bool setLayer(QCPLayer* layer);
  539. bool setLayer(const QString& layerName);
  540. void setAntialiased(bool enabled);
  541. // introduced virtual methods:
  542. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  543. // non-property methods:
  544. bool realVisibility() const;
  545. signals:
  546. void layerChanged(QCPLayer* newLayer);
  547. protected:
  548. // property members:
  549. bool mVisible;
  550. QCustomPlot* mParentPlot;
  551. QPointer<QCPLayerable> mParentLayerable;
  552. QCPLayer* mLayer;
  553. bool mAntialiased;
  554. // introduced virtual methods:
  555. virtual void parentPlotInitialized(QCustomPlot* parentPlot);
  556. virtual QCP::Interaction selectionCategory() const;
  557. virtual QRect clipRect() const;
  558. virtual void applyDefaultAntialiasingHint(QCPPainter* painter) const = 0;
  559. virtual void draw(QCPPainter* painter) = 0;
  560. // events:
  561. virtual void selectEvent(QMouseEvent* event, bool additive, const QVariant& details,
  562. bool* selectionStateChanged);
  563. virtual void deselectEvent(bool* selectionStateChanged);
  564. // non-property methods:
  565. void initializeParentPlot(QCustomPlot* parentPlot);
  566. void setParentLayerable(QCPLayerable* parentLayerable);
  567. bool moveToLayer(QCPLayer* layer, bool prepend);
  568. void applyAntialiasingHint(QCPPainter* painter, bool localAntialiased,
  569. QCP::AntialiasedElement overrideElement) const;
  570. private:
  571. Q_DISABLE_COPY(QCPLayerable)
  572. friend class QCustomPlot;
  573. friend class QCPAxisRect;
  574. };
  575. class QCP_LIB_DECL QCPRange
  576. {
  577. public:
  578. double lower, upper;
  579. QCPRange();
  580. QCPRange(double lower, double upper);
  581. bool operator==(const QCPRange& other) const
  582. {
  583. return lower == other.lower && upper == other.upper;
  584. }
  585. bool operator!=(const QCPRange& other) const
  586. {
  587. return !(*this == other);
  588. }
  589. QCPRange& operator+=(const double& value)
  590. {
  591. lower += value;
  592. upper += value;
  593. return *this;
  594. }
  595. QCPRange& operator-=(const double& value)
  596. {
  597. lower -= value;
  598. upper -= value;
  599. return *this;
  600. }
  601. QCPRange& operator*=(const double& value)
  602. {
  603. lower *= value;
  604. upper *= value;
  605. return *this;
  606. }
  607. QCPRange& operator/=(const double& value)
  608. {
  609. lower /= value;
  610. upper /= value;
  611. return *this;
  612. }
  613. friend inline const QCPRange operator+(const QCPRange&, double);
  614. friend inline const QCPRange operator+(double, const QCPRange&);
  615. friend inline const QCPRange operator-(const QCPRange& range, double value);
  616. friend inline const QCPRange operator*(const QCPRange& range, double value);
  617. friend inline const QCPRange operator*(double value, const QCPRange& range);
  618. friend inline const QCPRange operator/(const QCPRange& range, double value);
  619. double size() const;
  620. double center() const;
  621. void normalize();
  622. void expand(const QCPRange& otherRange);
  623. QCPRange expanded(const QCPRange& otherRange) const;
  624. QCPRange sanitizedForLogScale() const;
  625. QCPRange sanitizedForLinScale() const;
  626. bool contains(double value) const;
  627. static bool validRange(double lower, double upper);
  628. static bool validRange(const QCPRange& range);
  629. static const double minRange; // 1e-280;
  630. static const double maxRange; // 1e280;
  631. };
  632. Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
  633. /* documentation of inline functions */
  634. /*! \fn QCPRange &QCPRange::operator+=(const double& value)
  635. Adds \a value to both boundaries of the range.
  636. */
  637. /*! \fn QCPRange &QCPRange::operator-=(const double& value)
  638. Subtracts \a value from both boundaries of the range.
  639. */
  640. /*! \fn QCPRange &QCPRange::operator*=(const double& value)
  641. Multiplies both boundaries of the range by \a value.
  642. */
  643. /*! \fn QCPRange &QCPRange::operator/=(const double& value)
  644. Divides both boundaries of the range by \a value.
  645. */
  646. /* end documentation of inline functions */
  647. /*!
  648. Adds \a value to both boundaries of the range.
  649. */
  650. inline const QCPRange operator+(const QCPRange& range, double value)
  651. {
  652. QCPRange result(range);
  653. result += value;
  654. return result;
  655. }
  656. /*!
  657. Adds \a value to both boundaries of the range.
  658. */
  659. inline const QCPRange operator+(double value, const QCPRange& range)
  660. {
  661. QCPRange result(range);
  662. result += value;
  663. return result;
  664. }
  665. /*!
  666. Subtracts \a value from both boundaries of the range.
  667. */
  668. inline const QCPRange operator-(const QCPRange& range, double value)
  669. {
  670. QCPRange result(range);
  671. result -= value;
  672. return result;
  673. }
  674. /*!
  675. Multiplies both boundaries of the range by \a value.
  676. */
  677. inline const QCPRange operator*(const QCPRange& range, double value)
  678. {
  679. QCPRange result(range);
  680. result *= value;
  681. return result;
  682. }
  683. /*!
  684. Multiplies both boundaries of the range by \a value.
  685. */
  686. inline const QCPRange operator*(double value, const QCPRange& range)
  687. {
  688. QCPRange result(range);
  689. result *= value;
  690. return result;
  691. }
  692. /*!
  693. Divides both boundaries of the range by \a value.
  694. */
  695. inline const QCPRange operator/(const QCPRange& range, double value)
  696. {
  697. QCPRange result(range);
  698. result /= value;
  699. return result;
  700. }
  701. class QCP_LIB_DECL QCPMarginGroup : public QObject
  702. {
  703. Q_OBJECT
  704. public:
  705. QCPMarginGroup(QCustomPlot* parentPlot);
  706. ~QCPMarginGroup();
  707. // non-virtual methods:
  708. QList<QCPLayoutElement*> elements(QCP::MarginSide side) const
  709. {
  710. return mChildren.value(side);
  711. }
  712. bool isEmpty() const;
  713. void clear();
  714. protected:
  715. // non-property members:
  716. QCustomPlot* mParentPlot;
  717. QHash<QCP::MarginSide, QList<QCPLayoutElement*>> mChildren;
  718. // non-virtual methods:
  719. int commonMargin(QCP::MarginSide side) const;
  720. void addChild(QCP::MarginSide side, QCPLayoutElement* element);
  721. void removeChild(QCP::MarginSide side, QCPLayoutElement* element);
  722. private:
  723. Q_DISABLE_COPY(QCPMarginGroup)
  724. friend class QCPLayoutElement;
  725. };
  726. class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable
  727. {
  728. Q_OBJECT
  729. /// \cond INCLUDE_QPROPERTIES
  730. Q_PROPERTY(QCPLayout* layout READ layout)
  731. Q_PROPERTY(QRect rect READ rect)
  732. Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect)
  733. Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
  734. Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
  735. Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
  736. Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
  737. /// \endcond
  738. public:
  739. /*!
  740. Defines the phases of the update process, that happens just before a replot. At each phase,
  741. \ref update is called with the according UpdatePhase value.
  742. */
  743. enum UpdatePhase {
  744. upPreparation ///< Phase used for any type of preparation that needs to be done before
  745. ///< margin calculation and layout
  746. ,
  747. upMargins ///< Phase in which the margins are calculated and set
  748. ,
  749. upLayout ///< Final phase in which the layout system places the rects of the elements
  750. };
  751. Q_ENUMS(UpdatePhase)
  752. explicit QCPLayoutElement(QCustomPlot* parentPlot = 0);
  753. virtual ~QCPLayoutElement();
  754. // getters:
  755. QCPLayout* layout() const
  756. {
  757. return mParentLayout;
  758. }
  759. QRect rect() const
  760. {
  761. return mRect;
  762. }
  763. QRect outerRect() const
  764. {
  765. return mOuterRect;
  766. }
  767. QMargins margins() const
  768. {
  769. return mMargins;
  770. }
  771. QMargins minimumMargins() const
  772. {
  773. return mMinimumMargins;
  774. }
  775. QCP::MarginSides autoMargins() const
  776. {
  777. return mAutoMargins;
  778. }
  779. QSize minimumSize() const
  780. {
  781. return mMinimumSize;
  782. }
  783. QSize maximumSize() const
  784. {
  785. return mMaximumSize;
  786. }
  787. QCPMarginGroup* marginGroup(QCP::MarginSide side) const
  788. {
  789. return mMarginGroups.value(side, (QCPMarginGroup*)0);
  790. }
  791. QHash<QCP::MarginSide, QCPMarginGroup*> marginGroups() const
  792. {
  793. return mMarginGroups;
  794. }
  795. // setters:
  796. void setOuterRect(const QRect& rect);
  797. void setMargins(const QMargins& margins);
  798. void setMinimumMargins(const QMargins& margins);
  799. void setAutoMargins(QCP::MarginSides sides);
  800. void setMinimumSize(const QSize& size);
  801. void setMinimumSize(int width, int height);
  802. void setMaximumSize(const QSize& size);
  803. void setMaximumSize(int width, int height);
  804. void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup* group);
  805. // introduced virtual methods:
  806. virtual void update(UpdatePhase phase);
  807. virtual QSize minimumSizeHint() const;
  808. virtual QSize maximumSizeHint() const;
  809. virtual QList<QCPLayoutElement*> elements(bool recursive) const;
  810. // reimplemented virtual methods:
  811. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  812. protected:
  813. // property members:
  814. QCPLayout* mParentLayout;
  815. QSize mMinimumSize, mMaximumSize;
  816. QRect mRect, mOuterRect;
  817. QMargins mMargins, mMinimumMargins;
  818. QCP::MarginSides mAutoMargins;
  819. QHash<QCP::MarginSide, QCPMarginGroup*> mMarginGroups;
  820. // introduced virtual methods:
  821. virtual int calculateAutoMargin(QCP::MarginSide side);
  822. // events:
  823. virtual void mousePressEvent(QMouseEvent* event)
  824. {
  825. Q_UNUSED(event)
  826. }
  827. virtual void mouseMoveEvent(QMouseEvent* event)
  828. {
  829. Q_UNUSED(event)
  830. }
  831. virtual void mouseReleaseEvent(QMouseEvent* event)
  832. {
  833. Q_UNUSED(event)
  834. }
  835. virtual void mouseDoubleClickEvent(QMouseEvent* event)
  836. {
  837. Q_UNUSED(event)
  838. }
  839. virtual void wheelEvent(QWheelEvent* event)
  840. {
  841. Q_UNUSED(event)
  842. }
  843. // reimplemented virtual methods:
  844. virtual void applyDefaultAntialiasingHint(QCPPainter* painter) const
  845. {
  846. Q_UNUSED(painter)
  847. }
  848. virtual void draw(QCPPainter* painter)
  849. {
  850. Q_UNUSED(painter)
  851. }
  852. virtual void parentPlotInitialized(QCustomPlot* parentPlot);
  853. private:
  854. Q_DISABLE_COPY(QCPLayoutElement)
  855. friend class QCustomPlot;
  856. friend class QCPLayout;
  857. friend class QCPMarginGroup;
  858. };
  859. class QCP_LIB_DECL QCPLayout : public QCPLayoutElement
  860. {
  861. Q_OBJECT
  862. public:
  863. explicit QCPLayout();
  864. // reimplemented virtual methods:
  865. virtual void update(UpdatePhase phase);
  866. virtual QList<QCPLayoutElement*> elements(bool recursive) const;
  867. // introduced virtual methods:
  868. virtual int elementCount() const = 0;
  869. virtual QCPLayoutElement* elementAt(int index) const = 0;
  870. virtual QCPLayoutElement* takeAt(int index) = 0;
  871. virtual bool take(QCPLayoutElement* element) = 0;
  872. virtual void simplify();
  873. // non-virtual methods:
  874. bool removeAt(int index);
  875. bool remove(QCPLayoutElement* element);
  876. void clear();
  877. protected:
  878. // introduced virtual methods:
  879. virtual void updateLayout();
  880. // non-virtual methods:
  881. void sizeConstraintsChanged() const;
  882. void adoptElement(QCPLayoutElement* el);
  883. void releaseElement(QCPLayoutElement* el);
  884. QVector<int> getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes,
  885. QVector<double> stretchFactors, int totalSize) const;
  886. private:
  887. Q_DISABLE_COPY(QCPLayout)
  888. friend class QCPLayoutElement;
  889. };
  890. class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout
  891. {
  892. Q_OBJECT
  893. /// \cond INCLUDE_QPROPERTIES
  894. Q_PROPERTY(int rowCount READ rowCount)
  895. Q_PROPERTY(int columnCount READ columnCount)
  896. Q_PROPERTY(
  897. QList<double> columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors)
  898. Q_PROPERTY(QList<double> rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors)
  899. Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
  900. Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
  901. /// \endcond
  902. public:
  903. explicit QCPLayoutGrid();
  904. virtual ~QCPLayoutGrid();
  905. // getters:
  906. int rowCount() const;
  907. int columnCount() const;
  908. QList<double> columnStretchFactors() const
  909. {
  910. return mColumnStretchFactors;
  911. }
  912. QList<double> rowStretchFactors() const
  913. {
  914. return mRowStretchFactors;
  915. }
  916. int columnSpacing() const
  917. {
  918. return mColumnSpacing;
  919. }
  920. int rowSpacing() const
  921. {
  922. return mRowSpacing;
  923. }
  924. // setters:
  925. void setColumnStretchFactor(int column, double factor);
  926. void setColumnStretchFactors(const QList<double>& factors);
  927. void setRowStretchFactor(int row, double factor);
  928. void setRowStretchFactors(const QList<double>& factors);
  929. void setColumnSpacing(int pixels);
  930. void setRowSpacing(int pixels);
  931. // reimplemented virtual methods:
  932. virtual void updateLayout();
  933. virtual int elementCount() const;
  934. virtual QCPLayoutElement* elementAt(int index) const;
  935. virtual QCPLayoutElement* takeAt(int index);
  936. virtual bool take(QCPLayoutElement* element);
  937. virtual QList<QCPLayoutElement*> elements(bool recursive) const;
  938. virtual void simplify();
  939. virtual QSize minimumSizeHint() const;
  940. virtual QSize maximumSizeHint() const;
  941. // non-virtual methods:
  942. QCPLayoutElement* element(int row, int column) const;
  943. bool addElement(int row, int column, QCPLayoutElement* element);
  944. bool hasElement(int row, int column);
  945. void expandTo(int newRowCount, int newColumnCount);
  946. void insertRow(int newIndex);
  947. void insertColumn(int newIndex);
  948. protected:
  949. // property members:
  950. QList<QList<QCPLayoutElement*>> mElements;
  951. QList<double> mColumnStretchFactors;
  952. QList<double> mRowStretchFactors;
  953. int mColumnSpacing, mRowSpacing;
  954. // non-virtual methods:
  955. void getMinimumRowColSizes(QVector<int>* minColWidths, QVector<int>* minRowHeights) const;
  956. void getMaximumRowColSizes(QVector<int>* maxColWidths, QVector<int>* maxRowHeights) const;
  957. private:
  958. Q_DISABLE_COPY(QCPLayoutGrid)
  959. };
  960. class QCP_LIB_DECL QCPLayoutInset : public QCPLayout
  961. {
  962. Q_OBJECT
  963. public:
  964. /*!
  965. Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset.
  966. */
  967. enum InsetPlacement {
  968. ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect
  969. ,
  970. ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref
  971. ///< setInsetAlignment
  972. };
  973. explicit QCPLayoutInset();
  974. virtual ~QCPLayoutInset();
  975. // getters:
  976. InsetPlacement insetPlacement(int index) const;
  977. Qt::Alignment insetAlignment(int index) const;
  978. QRectF insetRect(int index) const;
  979. // setters:
  980. void setInsetPlacement(int index, InsetPlacement placement);
  981. void setInsetAlignment(int index, Qt::Alignment alignment);
  982. void setInsetRect(int index, const QRectF& rect);
  983. // reimplemented virtual methods:
  984. virtual void updateLayout();
  985. virtual int elementCount() const;
  986. virtual QCPLayoutElement* elementAt(int index) const;
  987. virtual QCPLayoutElement* takeAt(int index);
  988. virtual bool take(QCPLayoutElement* element);
  989. virtual void simplify()
  990. {}
  991. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  992. // non-virtual methods:
  993. void addElement(QCPLayoutElement* element, Qt::Alignment alignment);
  994. void addElement(QCPLayoutElement* element, const QRectF& rect);
  995. protected:
  996. // property members:
  997. QList<QCPLayoutElement*> mElements;
  998. QList<InsetPlacement> mInsetPlacement;
  999. QList<Qt::Alignment> mInsetAlignment;
  1000. QList<QRectF> mInsetRect;
  1001. private:
  1002. Q_DISABLE_COPY(QCPLayoutInset)
  1003. };
  1004. class QCP_LIB_DECL QCPLineEnding
  1005. {
  1006. Q_GADGET
  1007. public:
  1008. /*!
  1009. Defines the type of ending decoration for line-like items, e.g. an arrow.
  1010. \image html QCPLineEnding.png
  1011. The width and length of these decorations can be controlled with the functions \ref setWidth
  1012. and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref
  1013. esBar only support a width, the length property is ignored.
  1014. \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail,
  1015. QCPAxis::setLowerEnding, QCPAxis::setUpperEnding
  1016. */
  1017. Q_ENUMS(EndingStyle)
  1018. enum EndingStyle {
  1019. esNone ///< No ending decoration
  1020. ,
  1021. esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle)
  1022. ,
  1023. esSpikeArrow ///< A filled arrow head with an indented back
  1024. ,
  1025. esLineArrow ///< A non-filled arrow head with open back
  1026. ,
  1027. esDisc ///< A filled circle
  1028. ,
  1029. esSquare ///< A filled square
  1030. ,
  1031. esDiamond ///< A filled diamond (45° rotated square)
  1032. ,
  1033. esBar ///< A bar perpendicular to the line
  1034. ,
  1035. esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side
  1036. ///< can be changed with \ref setInverted)
  1037. ,
  1038. esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength)
  1039. };
  1040. QCPLineEnding();
  1041. QCPLineEnding(EndingStyle style, double width = 8, double length = 10, bool inverted = false);
  1042. // getters:
  1043. EndingStyle style() const
  1044. {
  1045. return mStyle;
  1046. }
  1047. double width() const
  1048. {
  1049. return mWidth;
  1050. }
  1051. double length() const
  1052. {
  1053. return mLength;
  1054. }
  1055. bool inverted() const
  1056. {
  1057. return mInverted;
  1058. }
  1059. // setters:
  1060. void setStyle(EndingStyle style);
  1061. void setWidth(double width);
  1062. void setLength(double length);
  1063. void setInverted(bool inverted);
  1064. // non-property methods:
  1065. double boundingDistance() const;
  1066. double realLength() const;
  1067. void draw(QCPPainter* painter, const QVector2D& pos, const QVector2D& dir) const;
  1068. void draw(QCPPainter* painter, const QVector2D& pos, double angle) const;
  1069. protected:
  1070. // property members:
  1071. EndingStyle mStyle;
  1072. double mWidth, mLength;
  1073. bool mInverted;
  1074. };
  1075. Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE);
  1076. class QCP_LIB_DECL QCPGrid : public QCPLayerable
  1077. {
  1078. Q_OBJECT
  1079. /// \cond INCLUDE_QPROPERTIES
  1080. Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible)
  1081. Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid)
  1082. Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine)
  1083. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  1084. Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen)
  1085. Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen)
  1086. /// \endcond
  1087. public:
  1088. QCPGrid(QCPAxis* parentAxis);
  1089. // getters:
  1090. bool subGridVisible() const
  1091. {
  1092. return mSubGridVisible;
  1093. }
  1094. bool antialiasedSubGrid() const
  1095. {
  1096. return mAntialiasedSubGrid;
  1097. }
  1098. bool antialiasedZeroLine() const
  1099. {
  1100. return mAntialiasedZeroLine;
  1101. }
  1102. QPen pen() const
  1103. {
  1104. return mPen;
  1105. }
  1106. QPen subGridPen() const
  1107. {
  1108. return mSubGridPen;
  1109. }
  1110. QPen zeroLinePen() const
  1111. {
  1112. return mZeroLinePen;
  1113. }
  1114. // setters:
  1115. void setSubGridVisible(bool visible);
  1116. void setAntialiasedSubGrid(bool enabled);
  1117. void setAntialiasedZeroLine(bool enabled);
  1118. void setPen(const QPen& pen);
  1119. void setSubGridPen(const QPen& pen);
  1120. void setZeroLinePen(const QPen& pen);
  1121. protected:
  1122. // property members:
  1123. bool mSubGridVisible;
  1124. bool mAntialiasedSubGrid, mAntialiasedZeroLine;
  1125. QPen mPen, mSubGridPen, mZeroLinePen;
  1126. // non-property members:
  1127. QCPAxis* mParentAxis;
  1128. // reimplemented virtual methods:
  1129. virtual void applyDefaultAntialiasingHint(QCPPainter* painter) const;
  1130. virtual void draw(QCPPainter* painter);
  1131. // non-virtual methods:
  1132. void drawGridLines(QCPPainter* painter) const;
  1133. void drawSubGridLines(QCPPainter* painter) const;
  1134. friend class QCPAxis;
  1135. };
  1136. class QCP_LIB_DECL QCPAxis : public QCPLayerable
  1137. {
  1138. Q_OBJECT
  1139. /// \cond INCLUDE_QPROPERTIES
  1140. Q_PROPERTY(AxisType axisType READ axisType)
  1141. Q_PROPERTY(QCPAxisRect* axisRect READ axisRect)
  1142. Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged)
  1143. Q_PROPERTY(double scaleLogBase READ scaleLogBase WRITE setScaleLogBase)
  1144. Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged)
  1145. Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed)
  1146. Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks)
  1147. Q_PROPERTY(int autoTickCount READ autoTickCount WRITE setAutoTickCount)
  1148. Q_PROPERTY(bool autoTickLabels READ autoTickLabels WRITE setAutoTickLabels)
  1149. Q_PROPERTY(bool autoTickStep READ autoTickStep WRITE setAutoTickStep)
  1150. Q_PROPERTY(bool autoSubTicks READ autoSubTicks WRITE setAutoSubTicks)
  1151. Q_PROPERTY(bool ticks READ ticks WRITE setTicks)
  1152. Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels)
  1153. Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding)
  1154. Q_PROPERTY(LabelType tickLabelType READ tickLabelType WRITE setTickLabelType)
  1155. Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont)
  1156. Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor)
  1157. Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation)
  1158. Q_PROPERTY(LabelSide tickLabelSide READ tickLabelSide WRITE setTickLabelSide)
  1159. Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat)
  1160. Q_PROPERTY(Qt::TimeSpec dateTimeSpec READ dateTimeSpec WRITE setDateTimeSpec)
  1161. Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat)
  1162. Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision)
  1163. Q_PROPERTY(double tickStep READ tickStep WRITE setTickStep)
  1164. Q_PROPERTY(QVector<double> tickVector READ tickVector WRITE setTickVector)
  1165. Q_PROPERTY(QVector<QString> tickVectorLabels READ tickVectorLabels WRITE setTickVectorLabels)
  1166. Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn)
  1167. Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut)
  1168. Q_PROPERTY(int subTickCount READ subTickCount WRITE setSubTickCount)
  1169. Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn)
  1170. Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut)
  1171. Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen)
  1172. Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen)
  1173. Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen)
  1174. Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont)
  1175. Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor)
  1176. Q_PROPERTY(QString label READ label WRITE setLabel)
  1177. Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding)
  1178. Q_PROPERTY(int padding READ padding WRITE setPadding)
  1179. Q_PROPERTY(int offset READ offset WRITE setOffset)
  1180. Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY
  1181. selectionChanged)
  1182. Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY
  1183. selectableChanged)
  1184. Q_PROPERTY(
  1185. QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont)
  1186. Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont)
  1187. Q_PROPERTY(
  1188. QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor)
  1189. Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor)
  1190. Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen)
  1191. Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen)
  1192. Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen)
  1193. Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding)
  1194. Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding)
  1195. Q_PROPERTY(QCPGrid* grid READ grid)
  1196. /// \endcond
  1197. public:
  1198. /*!
  1199. Defines at which side of the axis rect the axis will appear. This also affects how the tick
  1200. marks are drawn, on which side the labels are placed etc.
  1201. */
  1202. enum AxisType {
  1203. atLeft = 0x01 ///< <tt>0x01</tt> Axis is vertical and on the left side of the axis rect
  1204. ,
  1205. atRight = 0x02 ///< <tt>0x02</tt> Axis is vertical and on the right side of the axis rect
  1206. ,
  1207. atTop = 0x04 ///< <tt>0x04</tt> Axis is horizontal and on the top side of the axis rect
  1208. ,
  1209. atBottom =
  1210. 0x08 ///< <tt>0x08</tt> Axis is horizontal and on the bottom side of the axis rect
  1211. };
  1212. Q_FLAGS(AxisType AxisTypes)
  1213. Q_DECLARE_FLAGS(AxisTypes, AxisType)
  1214. /*!
  1215. When automatic tick label generation is enabled (\ref setAutoTickLabels), defines how the
  1216. coordinate of the tick is interpreted, i.e. translated into a string.
  1217. \see setTickLabelType
  1218. */
  1219. enum LabelType {
  1220. ltNumber ///< Tick coordinate is regarded as normal number and will be displayed as such.
  1221. ///< (see \ref setNumberFormat)
  1222. ,
  1223. ltDateTime ///< Tick coordinate is regarded as a date/time (seconds since
  1224. ///< 1970-01-01T00:00:00 UTC) and will be displayed and formatted as such. (for
  1225. ///< details, see \ref setDateTimeFormat)
  1226. };
  1227. Q_ENUMS(LabelType)
  1228. /*!
  1229. Defines on which side of the axis the tick labels (numbers) shall appear.
  1230. \see setTickLabelSide
  1231. */
  1232. enum LabelSide {
  1233. lsInside ///< Tick labels will be displayed inside the axis rect and clipped to the inner
  1234. ///< axis rect
  1235. ,
  1236. lsOutside ///< Tick labels will be displayed outside the axis rect
  1237. };
  1238. Q_ENUMS(LabelSide)
  1239. /*!
  1240. Defines the scale of an axis.
  1241. \see setScaleType
  1242. */
  1243. enum ScaleType {
  1244. stLinear ///< Linear scaling
  1245. ,
  1246. stLogarithmic ///< Logarithmic scaling with correspondingly transformed plots and (major)
  1247. ///< tick marks at every base power (see \ref setScaleLogBase).
  1248. };
  1249. Q_ENUMS(ScaleType)
  1250. /*!
  1251. Defines the selectable parts of an axis.
  1252. \see setSelectableParts, setSelectedParts
  1253. */
  1254. enum SelectablePart {
  1255. spNone = 0 ///< None of the selectable parts
  1256. ,
  1257. spAxis = 0x001 ///< The axis backbone and tick marks
  1258. ,
  1259. spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually)
  1260. ,
  1261. spAxisLabel = 0x004 ///< The axis label
  1262. };
  1263. Q_FLAGS(SelectablePart SelectableParts)
  1264. Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
  1265. explicit QCPAxis(QCPAxisRect* parent, AxisType type);
  1266. virtual ~QCPAxis();
  1267. // getters:
  1268. AxisType axisType() const
  1269. {
  1270. return mAxisType;
  1271. }
  1272. QCPAxisRect* axisRect() const
  1273. {
  1274. return mAxisRect;
  1275. }
  1276. ScaleType scaleType() const
  1277. {
  1278. return mScaleType;
  1279. }
  1280. double scaleLogBase() const
  1281. {
  1282. return mScaleLogBase;
  1283. }
  1284. const QCPRange range() const
  1285. {
  1286. return mRange;
  1287. }
  1288. bool rangeReversed() const
  1289. {
  1290. return mRangeReversed;
  1291. }
  1292. bool autoTicks() const
  1293. {
  1294. return mAutoTicks;
  1295. }
  1296. int autoTickCount() const
  1297. {
  1298. return mAutoTickCount;
  1299. }
  1300. bool autoTickLabels() const
  1301. {
  1302. return mAutoTickLabels;
  1303. }
  1304. bool autoTickStep() const
  1305. {
  1306. return mAutoTickStep;
  1307. }
  1308. bool autoSubTicks() const
  1309. {
  1310. return mAutoSubTicks;
  1311. }
  1312. bool ticks() const
  1313. {
  1314. return mTicks;
  1315. }
  1316. bool tickLabels() const
  1317. {
  1318. return mTickLabels;
  1319. }
  1320. int tickLabelPadding() const;
  1321. LabelType tickLabelType() const
  1322. {
  1323. return mTickLabelType;
  1324. }
  1325. QFont tickLabelFont() const
  1326. {
  1327. return mTickLabelFont;
  1328. }
  1329. QColor tickLabelColor() const
  1330. {
  1331. return mTickLabelColor;
  1332. }
  1333. double tickLabelRotation() const;
  1334. LabelSide tickLabelSide() const;
  1335. QString dateTimeFormat() const
  1336. {
  1337. return mDateTimeFormat;
  1338. }
  1339. Qt::TimeSpec dateTimeSpec() const
  1340. {
  1341. return mDateTimeSpec;
  1342. }
  1343. QString numberFormat() const;
  1344. int numberPrecision() const
  1345. {
  1346. return mNumberPrecision;
  1347. }
  1348. double tickStep() const
  1349. {
  1350. return mTickStep;
  1351. }
  1352. QVector<double> tickVector() const
  1353. {
  1354. return mTickVector;
  1355. }
  1356. QVector<QString> tickVectorLabels() const
  1357. {
  1358. return mTickVectorLabels;
  1359. }
  1360. int tickLengthIn() const;
  1361. int tickLengthOut() const;
  1362. int subTickCount() const
  1363. {
  1364. return mSubTickCount;
  1365. }
  1366. int subTickLengthIn() const;
  1367. int subTickLengthOut() const;
  1368. QPen basePen() const
  1369. {
  1370. return mBasePen;
  1371. }
  1372. QPen tickPen() const
  1373. {
  1374. return mTickPen;
  1375. }
  1376. QPen subTickPen() const
  1377. {
  1378. return mSubTickPen;
  1379. }
  1380. QFont labelFont() const
  1381. {
  1382. return mLabelFont;
  1383. }
  1384. QColor labelColor() const
  1385. {
  1386. return mLabelColor;
  1387. }
  1388. QString label() const
  1389. {
  1390. return mLabel;
  1391. }
  1392. int labelPadding() const;
  1393. int padding() const
  1394. {
  1395. return mPadding;
  1396. }
  1397. int offset() const;
  1398. SelectableParts selectedParts() const
  1399. {
  1400. return mSelectedParts;
  1401. }
  1402. SelectableParts selectableParts() const
  1403. {
  1404. return mSelectableParts;
  1405. }
  1406. QFont selectedTickLabelFont() const
  1407. {
  1408. return mSelectedTickLabelFont;
  1409. }
  1410. QFont selectedLabelFont() const
  1411. {
  1412. return mSelectedLabelFont;
  1413. }
  1414. QColor selectedTickLabelColor() const
  1415. {
  1416. return mSelectedTickLabelColor;
  1417. }
  1418. QColor selectedLabelColor() const
  1419. {
  1420. return mSelectedLabelColor;
  1421. }
  1422. QPen selectedBasePen() const
  1423. {
  1424. return mSelectedBasePen;
  1425. }
  1426. QPen selectedTickPen() const
  1427. {
  1428. return mSelectedTickPen;
  1429. }
  1430. QPen selectedSubTickPen() const
  1431. {
  1432. return mSelectedSubTickPen;
  1433. }
  1434. QCPLineEnding lowerEnding() const;
  1435. QCPLineEnding upperEnding() const;
  1436. QCPGrid* grid() const
  1437. {
  1438. return mGrid;
  1439. }
  1440. // setters:
  1441. Q_SLOT void setScaleType(QCPAxis::ScaleType type);
  1442. void setScaleLogBase(double base);
  1443. Q_SLOT void setRange(const QCPRange& range);
  1444. void setRange(double lower, double upper);
  1445. void setRange(double position, double size, Qt::AlignmentFlag alignment);
  1446. void setRangeLower(double lower);
  1447. void setRangeUpper(double upper);
  1448. void setRangeReversed(bool reversed);
  1449. void setAutoTicks(bool on);
  1450. void setAutoTickCount(int approximateCount);
  1451. void setAutoTickLabels(bool on);
  1452. void setAutoTickStep(bool on);
  1453. void setAutoSubTicks(bool on);
  1454. void setTicks(bool show);
  1455. void setTickLabels(bool show);
  1456. void setTickLabelPadding(int padding);
  1457. void setTickLabelType(LabelType type);
  1458. void setTickLabelFont(const QFont& font);
  1459. void setTickLabelColor(const QColor& color);
  1460. void setTickLabelRotation(double degrees);
  1461. void setTickLabelSide(LabelSide side);
  1462. void setDateTimeFormat(const QString& format);
  1463. void setDateTimeSpec(const Qt::TimeSpec& timeSpec);
  1464. void setNumberFormat(const QString& formatCode);
  1465. void setNumberPrecision(int precision);
  1466. void setTickStep(double step);
  1467. void setTickVector(const QVector<double>& vec);
  1468. void setTickVectorLabels(const QVector<QString>& vec);
  1469. void setTickLength(int inside, int outside = 0);
  1470. void setTickLengthIn(int inside);
  1471. void setTickLengthOut(int outside);
  1472. void setSubTickCount(int count);
  1473. void setSubTickLength(int inside, int outside = 0);
  1474. void setSubTickLengthIn(int inside);
  1475. void setSubTickLengthOut(int outside);
  1476. void setBasePen(const QPen& pen);
  1477. void setTickPen(const QPen& pen);
  1478. void setSubTickPen(const QPen& pen);
  1479. void setLabelFont(const QFont& font);
  1480. void setLabelColor(const QColor& color);
  1481. void setLabel(const QString& str);
  1482. void setLabelPadding(int padding);
  1483. void setPadding(int padding);
  1484. void setOffset(int offset);
  1485. void setSelectedTickLabelFont(const QFont& font);
  1486. void setSelectedLabelFont(const QFont& font);
  1487. void setSelectedTickLabelColor(const QColor& color);
  1488. void setSelectedLabelColor(const QColor& color);
  1489. void setSelectedBasePen(const QPen& pen);
  1490. void setSelectedTickPen(const QPen& pen);
  1491. void setSelectedSubTickPen(const QPen& pen);
  1492. Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts& selectableParts);
  1493. Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts& selectedParts);
  1494. void setLowerEnding(const QCPLineEnding& ending);
  1495. void setUpperEnding(const QCPLineEnding& ending);
  1496. // reimplemented virtual methods:
  1497. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  1498. // non-property methods:
  1499. Qt::Orientation orientation() const
  1500. {
  1501. return mOrientation;
  1502. }
  1503. void moveRange(double diff);
  1504. void scaleRange(double factor, double center);
  1505. void setScaleRatio(const QCPAxis* otherAxis, double ratio = 1.0);
  1506. void rescale(bool onlyVisiblePlottables = false);
  1507. double pixelToCoord(double value) const;
  1508. double coordToPixel(double value) const;
  1509. SelectablePart getPartAt(const QPointF& pos) const;
  1510. QList<QCPAbstractPlottable*> plottables() const;
  1511. QList<QCPGraph*> graphs() const;
  1512. QList<QCPAbstractItem*> items() const;
  1513. static AxisType marginSideToAxisType(QCP::MarginSide side);
  1514. static Qt::Orientation orientation(AxisType type)
  1515. {
  1516. return type == atBottom || type == atTop ? Qt::Horizontal : Qt::Vertical;
  1517. }
  1518. static AxisType opposite(AxisType type);
  1519. signals:
  1520. void ticksRequest();
  1521. void rangeChanged(const QCPRange& newRange);
  1522. void rangeChanged(const QCPRange& newRange, const QCPRange& oldRange);
  1523. void scaleTypeChanged(QCPAxis::ScaleType scaleType);
  1524. void selectionChanged(const QCPAxis::SelectableParts& parts);
  1525. void selectableChanged(const QCPAxis::SelectableParts& parts);
  1526. protected:
  1527. // property members:
  1528. // axis base:
  1529. AxisType mAxisType;
  1530. QCPAxisRect* mAxisRect;
  1531. // int mOffset; // in QCPAxisPainter
  1532. int mPadding;
  1533. Qt::Orientation mOrientation;
  1534. SelectableParts mSelectableParts, mSelectedParts;
  1535. QPen mBasePen, mSelectedBasePen;
  1536. // QCPLineEnding mLowerEnding, mUpperEnding; // in QCPAxisPainter
  1537. // axis label:
  1538. // int mLabelPadding; // in QCPAxisPainter
  1539. QString mLabel;
  1540. QFont mLabelFont, mSelectedLabelFont;
  1541. QColor mLabelColor, mSelectedLabelColor;
  1542. // tick labels:
  1543. // int mTickLabelPadding; // in QCPAxisPainter
  1544. bool mTickLabels, mAutoTickLabels;
  1545. // double mTickLabelRotation; // in QCPAxisPainter
  1546. LabelType mTickLabelType;
  1547. QFont mTickLabelFont, mSelectedTickLabelFont;
  1548. QColor mTickLabelColor, mSelectedTickLabelColor;
  1549. QString mDateTimeFormat;
  1550. Qt::TimeSpec mDateTimeSpec;
  1551. int mNumberPrecision;
  1552. QLatin1Char mNumberFormatChar;
  1553. bool mNumberBeautifulPowers;
  1554. // bool mNumberMultiplyCross; // QCPAxisPainter
  1555. // ticks and subticks:
  1556. bool mTicks;
  1557. double mTickStep;
  1558. int mSubTickCount, mAutoTickCount;
  1559. bool mAutoTicks, mAutoTickStep, mAutoSubTicks;
  1560. // int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut; // QCPAxisPainter
  1561. QPen mTickPen, mSelectedTickPen;
  1562. QPen mSubTickPen, mSelectedSubTickPen;
  1563. // scale and range:
  1564. QCPRange mRange;
  1565. bool mRangeReversed;
  1566. ScaleType mScaleType;
  1567. double mScaleLogBase, mScaleLogBaseLogInv;
  1568. // non-property members:
  1569. QCPGrid* mGrid;
  1570. QCPAxisPainterPrivate* mAxisPainter;
  1571. int mLowestVisibleTick, mHighestVisibleTick;
  1572. QVector<double> mTickVector;
  1573. QVector<QString> mTickVectorLabels;
  1574. QVector<double> mSubTickVector;
  1575. bool mCachedMarginValid;
  1576. int mCachedMargin;
  1577. // introduced virtual methods:
  1578. virtual void setupTickVectors();
  1579. virtual void generateAutoTicks();
  1580. virtual int calculateAutoSubTickCount(double tickStep) const;
  1581. virtual int calculateMargin();
  1582. // reimplemented virtual methods:
  1583. virtual void applyDefaultAntialiasingHint(QCPPainter* painter) const;
  1584. virtual void draw(QCPPainter* painter);
  1585. virtual QCP::Interaction selectionCategory() const;
  1586. // events:
  1587. virtual void selectEvent(QMouseEvent* event, bool additive, const QVariant& details,
  1588. bool* selectionStateChanged);
  1589. virtual void deselectEvent(bool* selectionStateChanged);
  1590. // non-virtual methods:
  1591. void visibleTickBounds(int& lowIndex, int& highIndex) const;
  1592. double baseLog(double value) const;
  1593. double basePow(double value) const;
  1594. QPen getBasePen() const;
  1595. QPen getTickPen() const;
  1596. QPen getSubTickPen() const;
  1597. QFont getTickLabelFont() const;
  1598. QFont getLabelFont() const;
  1599. QColor getTickLabelColor() const;
  1600. QColor getLabelColor() const;
  1601. private:
  1602. Q_DISABLE_COPY(QCPAxis)
  1603. friend class QCustomPlot;
  1604. friend class QCPGrid;
  1605. friend class QCPAxisRect;
  1606. };
  1607. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts)
  1608. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes)
  1609. Q_DECLARE_METATYPE(QCPAxis::SelectablePart)
  1610. class QCPAxisPainterPrivate
  1611. {
  1612. public:
  1613. explicit QCPAxisPainterPrivate(QCustomPlot* parentPlot);
  1614. virtual ~QCPAxisPainterPrivate();
  1615. virtual void draw(QCPPainter* painter);
  1616. virtual int size() const;
  1617. void clearCache();
  1618. QRect axisSelectionBox() const
  1619. {
  1620. return mAxisSelectionBox;
  1621. }
  1622. QRect tickLabelsSelectionBox() const
  1623. {
  1624. return mTickLabelsSelectionBox;
  1625. }
  1626. QRect labelSelectionBox() const
  1627. {
  1628. return mLabelSelectionBox;
  1629. }
  1630. // public property members:
  1631. QCPAxis::AxisType type;
  1632. QPen basePen;
  1633. QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters
  1634. int labelPadding; // directly accessed by QCPAxis setters/getters
  1635. QFont labelFont;
  1636. QColor labelColor;
  1637. QString label;
  1638. int tickLabelPadding; // directly accessed by QCPAxis setters/getters
  1639. double tickLabelRotation; // directly accessed by QCPAxis setters/getters
  1640. QCPAxis::LabelSide tickLabelSide; // directly accessed by QCPAxis setters/getters
  1641. bool substituteExponent;
  1642. bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters
  1643. int tickLengthIn, tickLengthOut, subTickLengthIn,
  1644. subTickLengthOut; // directly accessed by QCPAxis setters/getters
  1645. QPen tickPen, subTickPen;
  1646. QFont tickLabelFont;
  1647. QColor tickLabelColor;
  1648. QRect axisRect, viewportRect;
  1649. double offset; // directly accessed by QCPAxis setters/getters
  1650. bool abbreviateDecimalPowers;
  1651. bool reversedEndings;
  1652. QVector<double> subTickPositions;
  1653. QVector<double> tickPositions;
  1654. QVector<QString> tickLabels;
  1655. protected:
  1656. struct CachedLabel {
  1657. QPointF offset;
  1658. QPixmap pixmap;
  1659. };
  1660. struct TickLabelData {
  1661. QString basePart, expPart;
  1662. QRect baseBounds, expBounds, totalBounds, rotatedTotalBounds;
  1663. QFont baseFont, expFont;
  1664. };
  1665. QCustomPlot* mParentPlot;
  1666. QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to
  1667. // changed parameters
  1668. QCache<QString, CachedLabel> mLabelCache;
  1669. QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox;
  1670. virtual QByteArray generateLabelParameterHash() const;
  1671. virtual void placeTickLabel(QCPPainter* painter, double position, int distanceToAxis,
  1672. const QString& text, QSize* tickLabelsSize);
  1673. virtual void drawTickLabel(QCPPainter* painter, double x, double y,
  1674. const TickLabelData& labelData) const;
  1675. virtual TickLabelData getTickLabelData(const QFont& font, const QString& text) const;
  1676. virtual QPointF getTickLabelDrawOffset(const TickLabelData& labelData) const;
  1677. virtual void getMaxTickLabelSize(const QFont& font, const QString& text,
  1678. QSize* tickLabelsSize) const;
  1679. };
  1680. class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable
  1681. {
  1682. Q_OBJECT
  1683. /// \cond INCLUDE_QPROPERTIES
  1684. Q_PROPERTY(QString name READ name WRITE setName)
  1685. Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill)
  1686. Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters)
  1687. Q_PROPERTY(bool antialiasedErrorBars READ antialiasedErrorBars WRITE setAntialiasedErrorBars)
  1688. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  1689. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  1690. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  1691. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  1692. Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis)
  1693. Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis)
  1694. Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
  1695. Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
  1696. /// \endcond
  1697. public:
  1698. QCPAbstractPlottable(QCPAxis* keyAxis, QCPAxis* valueAxis);
  1699. // getters:
  1700. QString name() const
  1701. {
  1702. return mName;
  1703. }
  1704. bool antialiasedFill() const
  1705. {
  1706. return mAntialiasedFill;
  1707. }
  1708. bool antialiasedScatters() const
  1709. {
  1710. return mAntialiasedScatters;
  1711. }
  1712. bool antialiasedErrorBars() const
  1713. {
  1714. return mAntialiasedErrorBars;
  1715. }
  1716. QPen pen() const
  1717. {
  1718. return mPen;
  1719. }
  1720. QPen selectedPen() const
  1721. {
  1722. return mSelectedPen;
  1723. }
  1724. QBrush brush() const
  1725. {
  1726. return mBrush;
  1727. }
  1728. QBrush selectedBrush() const
  1729. {
  1730. return mSelectedBrush;
  1731. }
  1732. QCPAxis* keyAxis() const
  1733. {
  1734. return mKeyAxis.data();
  1735. }
  1736. QCPAxis* valueAxis() const
  1737. {
  1738. return mValueAxis.data();
  1739. }
  1740. bool selectable() const
  1741. {
  1742. return mSelectable;
  1743. }
  1744. bool selected() const
  1745. {
  1746. return mSelected;
  1747. }
  1748. // setters:
  1749. void setName(const QString& name);
  1750. void setAntialiasedFill(bool enabled);
  1751. void setAntialiasedScatters(bool enabled);
  1752. void setAntialiasedErrorBars(bool enabled);
  1753. void setPen(const QPen& pen);
  1754. void setSelectedPen(const QPen& pen);
  1755. void setBrush(const QBrush& brush);
  1756. void setSelectedBrush(const QBrush& brush);
  1757. void setKeyAxis(QCPAxis* axis);
  1758. void setValueAxis(QCPAxis* axis);
  1759. Q_SLOT void setSelectable(bool selectable);
  1760. Q_SLOT void setSelected(bool selected);
  1761. // introduced virtual methods:
  1762. virtual void clearData() = 0;
  1763. virtual double selectTest(const QPointF& pos, bool onlySelectable,
  1764. QVariant* details = 0) const = 0;
  1765. virtual bool addToLegend();
  1766. virtual bool removeFromLegend() const;
  1767. // non-property methods:
  1768. void rescaleAxes(bool onlyEnlarge = false) const;
  1769. void rescaleKeyAxis(bool onlyEnlarge = false) const;
  1770. void rescaleValueAxis(bool onlyEnlarge = false) const;
  1771. signals:
  1772. void selectionChanged(bool selected);
  1773. void selectableChanged(bool selectable);
  1774. protected:
  1775. /*!
  1776. Represents negative and positive sign domain for passing to \ref getKeyRange and \ref
  1777. getValueRange.
  1778. */
  1779. enum SignDomain {
  1780. sdNegative ///< The negative sign domain, i.e. numbers smaller than zero
  1781. ,
  1782. sdBoth ///< Both sign domains, including zero, i.e. all (rational) numbers
  1783. ,
  1784. sdPositive ///< The positive sign domain, i.e. numbers greater than zero
  1785. };
  1786. // property members:
  1787. QString mName;
  1788. bool mAntialiasedFill, mAntialiasedScatters, mAntialiasedErrorBars;
  1789. QPen mPen, mSelectedPen;
  1790. QBrush mBrush, mSelectedBrush;
  1791. QPointer<QCPAxis> mKeyAxis, mValueAxis;
  1792. bool mSelectable, mSelected;
  1793. // reimplemented virtual methods:
  1794. virtual QRect clipRect() const;
  1795. virtual void draw(QCPPainter* painter) = 0;
  1796. virtual QCP::Interaction selectionCategory() const;
  1797. void applyDefaultAntialiasingHint(QCPPainter* painter) const;
  1798. // events:
  1799. virtual void selectEvent(QMouseEvent* event, bool additive, const QVariant& details,
  1800. bool* selectionStateChanged);
  1801. virtual void deselectEvent(bool* selectionStateChanged);
  1802. // introduced virtual methods:
  1803. virtual void drawLegendIcon(QCPPainter* painter, const QRectF& rect) const = 0;
  1804. virtual QCPRange getKeyRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const = 0;
  1805. virtual QCPRange getValueRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const = 0;
  1806. // non-virtual methods:
  1807. void coordsToPixels(double key, double value, double& x, double& y) const;
  1808. const QPointF coordsToPixels(double key, double value) const;
  1809. void pixelsToCoords(double x, double y, double& key, double& value) const;
  1810. void pixelsToCoords(const QPointF& pixelPos, double& key, double& value) const;
  1811. QPen mainPen() const;
  1812. QBrush mainBrush() const;
  1813. void applyFillAntialiasingHint(QCPPainter* painter) const;
  1814. void applyScattersAntialiasingHint(QCPPainter* painter) const;
  1815. void applyErrorBarsAntialiasingHint(QCPPainter* painter) const;
  1816. double distSqrToLine(const QPointF& start, const QPointF& end, const QPointF& point) const;
  1817. private:
  1818. Q_DISABLE_COPY(QCPAbstractPlottable)
  1819. friend class QCustomPlot;
  1820. friend class QCPAxis;
  1821. friend class QCPPlottableLegendItem;
  1822. };
  1823. class QCP_LIB_DECL QCPItemAnchor
  1824. {
  1825. public:
  1826. QCPItemAnchor(QCustomPlot* parentPlot, QCPAbstractItem* parentItem, const QString name,
  1827. int anchorId = -1);
  1828. virtual ~QCPItemAnchor();
  1829. // getters:
  1830. QString name() const
  1831. {
  1832. return mName;
  1833. }
  1834. virtual QPointF pixelPoint() const;
  1835. protected:
  1836. // property members:
  1837. QString mName;
  1838. // non-property members:
  1839. QCustomPlot* mParentPlot;
  1840. QCPAbstractItem* mParentItem;
  1841. int mAnchorId;
  1842. QSet<QCPItemPosition*> mChildrenX, mChildrenY;
  1843. // introduced virtual methods:
  1844. virtual QCPItemPosition* toQCPItemPosition()
  1845. {
  1846. return 0;
  1847. }
  1848. // non-virtual methods:
  1849. void addChildX(QCPItemPosition* pos); // called from pos when this anchor is set as parent
  1850. void removeChildX(
  1851. QCPItemPosition* pos); // called from pos when its parent anchor is reset or pos deleted
  1852. void addChildY(QCPItemPosition* pos); // called from pos when this anchor is set as parent
  1853. void removeChildY(
  1854. QCPItemPosition* pos); // called from pos when its parent anchor is reset or pos deleted
  1855. private:
  1856. Q_DISABLE_COPY(QCPItemAnchor)
  1857. friend class QCPItemPosition;
  1858. };
  1859. class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor
  1860. {
  1861. public:
  1862. /*!
  1863. Defines the ways an item position can be specified. Thus it defines what the numbers passed to
  1864. \ref setCoords actually mean.
  1865. \see setType
  1866. */
  1867. enum PositionType {
  1868. ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the
  1869. ///< viewport/widget.
  1870. ,
  1871. ptViewportRatio ///< Static positioning given by a fraction of the viewport size. For
  1872. ///< example, if you call setCoords(0, 0), the position will be at the top
  1873. ///< left corner of the viewport/widget. setCoords(1, 1) will be at the
  1874. ///< bottom right corner, setCoords(0.5, 0) will be horizontally centered
  1875. ///< and vertically at the top of the viewport/widget, etc.
  1876. ,
  1877. ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref
  1878. ///< setAxisRect). For example, if you call setCoords(0, 0), the position
  1879. ///< will be at the top left corner of the axis rect. setCoords(1, 1) will
  1880. ///< be at the bottom right corner, setCoords(0.5, 0) will be horizontally
  1881. ///< centered and vertically at the top of the axis rect, etc. You can also
  1882. ///< go beyond the axis rect by providing negative coordinates or
  1883. ///< coordinates larger than 1.
  1884. ,
  1885. ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref
  1886. ///< setAxes).
  1887. };
  1888. QCPItemPosition(QCustomPlot* parentPlot, QCPAbstractItem* parentItem, const QString name);
  1889. virtual ~QCPItemPosition();
  1890. // getters:
  1891. PositionType type() const
  1892. {
  1893. return typeX();
  1894. }
  1895. PositionType typeX() const
  1896. {
  1897. return mPositionTypeX;
  1898. }
  1899. PositionType typeY() const
  1900. {
  1901. return mPositionTypeY;
  1902. }
  1903. QCPItemAnchor* parentAnchor() const
  1904. {
  1905. return parentAnchorX();
  1906. }
  1907. QCPItemAnchor* parentAnchorX() const
  1908. {
  1909. return mParentAnchorX;
  1910. }
  1911. QCPItemAnchor* parentAnchorY() const
  1912. {
  1913. return mParentAnchorY;
  1914. }
  1915. double key() const
  1916. {
  1917. return mKey;
  1918. }
  1919. double value() const
  1920. {
  1921. return mValue;
  1922. }
  1923. QPointF coords() const
  1924. {
  1925. return QPointF(mKey, mValue);
  1926. }
  1927. QCPAxis* keyAxis() const
  1928. {
  1929. return mKeyAxis.data();
  1930. }
  1931. QCPAxis* valueAxis() const
  1932. {
  1933. return mValueAxis.data();
  1934. }
  1935. QCPAxisRect* axisRect() const;
  1936. virtual QPointF pixelPoint() const;
  1937. // setters:
  1938. void setType(PositionType type);
  1939. void setTypeX(PositionType type);
  1940. void setTypeY(PositionType type);
  1941. bool setParentAnchor(QCPItemAnchor* parentAnchor, bool keepPixelPosition = false);
  1942. bool setParentAnchorX(QCPItemAnchor* parentAnchor, bool keepPixelPosition = false);
  1943. bool setParentAnchorY(QCPItemAnchor* parentAnchor, bool keepPixelPosition = false);
  1944. void setCoords(double key, double value);
  1945. void setCoords(const QPointF& coords);
  1946. void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis);
  1947. void setAxisRect(QCPAxisRect* axisRect);
  1948. void setPixelPoint(const QPointF& pixelPoint);
  1949. protected:
  1950. // property members:
  1951. PositionType mPositionTypeX, mPositionTypeY;
  1952. QPointer<QCPAxis> mKeyAxis, mValueAxis;
  1953. QPointer<QCPAxisRect> mAxisRect;
  1954. double mKey, mValue;
  1955. QCPItemAnchor * mParentAnchorX, *mParentAnchorY;
  1956. // reimplemented virtual methods:
  1957. virtual QCPItemPosition* toQCPItemPosition()
  1958. {
  1959. return this;
  1960. }
  1961. private:
  1962. Q_DISABLE_COPY(QCPItemPosition)
  1963. };
  1964. class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable
  1965. {
  1966. Q_OBJECT
  1967. /// \cond INCLUDE_QPROPERTIES
  1968. Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect)
  1969. Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect)
  1970. Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
  1971. Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
  1972. /// \endcond
  1973. public:
  1974. QCPAbstractItem(QCustomPlot* parentPlot);
  1975. virtual ~QCPAbstractItem();
  1976. // getters:
  1977. bool clipToAxisRect() const
  1978. {
  1979. return mClipToAxisRect;
  1980. }
  1981. QCPAxisRect* clipAxisRect() const;
  1982. bool selectable() const
  1983. {
  1984. return mSelectable;
  1985. }
  1986. bool selected() const
  1987. {
  1988. return mSelected;
  1989. }
  1990. // setters:
  1991. void setClipToAxisRect(bool clip);
  1992. void setClipAxisRect(QCPAxisRect* rect);
  1993. Q_SLOT void setSelectable(bool selectable);
  1994. Q_SLOT void setSelected(bool selected);
  1995. // reimplemented virtual methods:
  1996. virtual double selectTest(const QPointF& pos, bool onlySelectable,
  1997. QVariant* details = 0) const = 0;
  1998. // non-virtual methods:
  1999. QList<QCPItemPosition*> positions() const
  2000. {
  2001. return mPositions;
  2002. }
  2003. QList<QCPItemAnchor*> anchors() const
  2004. {
  2005. return mAnchors;
  2006. }
  2007. QCPItemPosition* position(const QString& name) const;
  2008. QCPItemAnchor* anchor(const QString& name) const;
  2009. bool hasAnchor(const QString& name) const;
  2010. signals:
  2011. void selectionChanged(bool selected);
  2012. void selectableChanged(bool selectable);
  2013. protected:
  2014. // property members:
  2015. bool mClipToAxisRect;
  2016. QPointer<QCPAxisRect> mClipAxisRect;
  2017. QList<QCPItemPosition*> mPositions;
  2018. QList<QCPItemAnchor*> mAnchors;
  2019. bool mSelectable, mSelected;
  2020. // reimplemented virtual methods:
  2021. virtual QCP::Interaction selectionCategory() const;
  2022. virtual QRect clipRect() const;
  2023. virtual void applyDefaultAntialiasingHint(QCPPainter* painter) const;
  2024. virtual void draw(QCPPainter* painter) = 0;
  2025. // events:
  2026. virtual void selectEvent(QMouseEvent* event, bool additive, const QVariant& details,
  2027. bool* selectionStateChanged);
  2028. virtual void deselectEvent(bool* selectionStateChanged);
  2029. // introduced virtual methods:
  2030. virtual QPointF anchorPixelPoint(int anchorId) const;
  2031. // non-virtual methods:
  2032. double distSqrToLine(const QPointF& start, const QPointF& end, const QPointF& point) const;
  2033. double rectSelectTest(const QRectF& rect, const QPointF& pos, bool filledRect) const;
  2034. QCPItemPosition* createPosition(const QString& name);
  2035. QCPItemAnchor* createAnchor(const QString& name, int anchorId);
  2036. private:
  2037. Q_DISABLE_COPY(QCPAbstractItem)
  2038. friend class QCustomPlot;
  2039. friend class QCPItemAnchor;
  2040. };
  2041. class QCP_LIB_DECL QCustomPlot : public QWidget
  2042. {
  2043. Q_OBJECT
  2044. /// \cond INCLUDE_QPROPERTIES
  2045. Q_PROPERTY(QRect viewport READ viewport WRITE setViewport)
  2046. Q_PROPERTY(QPixmap background READ background WRITE setBackground)
  2047. Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
  2048. Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE
  2049. setBackgroundScaledMode)
  2050. Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout)
  2051. Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE
  2052. setAutoAddPlottableToLegend)
  2053. Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance)
  2054. Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag)
  2055. Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE
  2056. setMultiSelectModifier)
  2057. /// \endcond
  2058. public:
  2059. /*!
  2060. Defines how a layer should be inserted relative to an other layer.
  2061. \see addLayer, moveLayer
  2062. */
  2063. enum LayerInsertMode {
  2064. limBelow ///< Layer is inserted below other layer
  2065. ,
  2066. limAbove ///< Layer is inserted above other layer
  2067. };
  2068. Q_ENUMS(LayerInsertMode)
  2069. /*!
  2070. Defines with what timing the QCustomPlot surface is refreshed after a replot.
  2071. \see replot
  2072. */
  2073. enum RefreshPriority {
  2074. rpImmediate ///< The QCustomPlot surface is immediately refreshed, by calling
  2075. ///< QWidget::repaint() after the replot
  2076. ,
  2077. rpQueued ///< Queues the refresh such that it is performed at a slightly delayed point in
  2078. ///< time after the replot, by calling QWidget::update() after the replot
  2079. ,
  2080. rpHint ///< Whether to use immediate repaint or queued update depends on whether the
  2081. ///< plotting hint \ref QCP::phForceRepaint is set, see \ref setPlottingHints.
  2082. };
  2083. explicit QCustomPlot(QWidget* parent = 0);
  2084. virtual ~QCustomPlot();
  2085. // getters:
  2086. QRect viewport() const
  2087. {
  2088. return mViewport;
  2089. }
  2090. QPixmap background() const
  2091. {
  2092. return mBackgroundPixmap;
  2093. }
  2094. bool backgroundScaled() const
  2095. {
  2096. return mBackgroundScaled;
  2097. }
  2098. Qt::AspectRatioMode backgroundScaledMode() const
  2099. {
  2100. return mBackgroundScaledMode;
  2101. }
  2102. QCPLayoutGrid* plotLayout() const
  2103. {
  2104. return mPlotLayout;
  2105. }
  2106. QCP::AntialiasedElements antialiasedElements() const
  2107. {
  2108. return mAntialiasedElements;
  2109. }
  2110. QCP::AntialiasedElements notAntialiasedElements() const
  2111. {
  2112. return mNotAntialiasedElements;
  2113. }
  2114. bool autoAddPlottableToLegend() const
  2115. {
  2116. return mAutoAddPlottableToLegend;
  2117. }
  2118. const QCP::Interactions interactions() const
  2119. {
  2120. return mInteractions;
  2121. }
  2122. int selectionTolerance() const
  2123. {
  2124. return mSelectionTolerance;
  2125. }
  2126. bool noAntialiasingOnDrag() const
  2127. {
  2128. return mNoAntialiasingOnDrag;
  2129. }
  2130. QCP::PlottingHints plottingHints() const
  2131. {
  2132. return mPlottingHints;
  2133. }
  2134. Qt::KeyboardModifier multiSelectModifier() const
  2135. {
  2136. return mMultiSelectModifier;
  2137. }
  2138. // setters:
  2139. void setViewport(const QRect& rect);
  2140. void setBackground(const QPixmap& pm);
  2141. void setBackground(const QPixmap& pm, bool scaled,
  2142. Qt::AspectRatioMode mode = Qt::KeepAspectRatioByExpanding);
  2143. void setBackground(const QBrush& brush);
  2144. void setBackgroundScaled(bool scaled);
  2145. void setBackgroundScaledMode(Qt::AspectRatioMode mode);
  2146. void setAntialiasedElements(const QCP::AntialiasedElements& antialiasedElements);
  2147. void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled = true);
  2148. void setNotAntialiasedElements(const QCP::AntialiasedElements& notAntialiasedElements);
  2149. void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement,
  2150. bool enabled = true);
  2151. void setAutoAddPlottableToLegend(bool on);
  2152. void setInteractions(const QCP::Interactions& interactions);
  2153. void setInteraction(const QCP::Interaction& interaction, bool enabled = true);
  2154. void setSelectionTolerance(int pixels);
  2155. void setNoAntialiasingOnDrag(bool enabled);
  2156. void setPlottingHints(const QCP::PlottingHints& hints);
  2157. void setPlottingHint(QCP::PlottingHint hint, bool enabled = true);
  2158. void setMultiSelectModifier(Qt::KeyboardModifier modifier);
  2159. // non-property methods:
  2160. // plottable interface:
  2161. QCPAbstractPlottable* plottable(int index);
  2162. QCPAbstractPlottable* plottable();
  2163. bool addPlottable(QCPAbstractPlottable* plottable);
  2164. bool removePlottable(QCPAbstractPlottable* plottable);
  2165. bool removePlottable(int index);
  2166. int clearPlottables();
  2167. int plottableCount() const;
  2168. QList<QCPAbstractPlottable*> selectedPlottables() const;
  2169. QCPAbstractPlottable* plottableAt(const QPointF& pos, bool onlySelectable = false) const;
  2170. bool hasPlottable(QCPAbstractPlottable* plottable) const;
  2171. // specialized interface for QCPGraph:
  2172. QCPGraph* graph(int index) const;
  2173. QCPGraph* graph() const;
  2174. QCPGraph* addGraph(QCPAxis* keyAxis = 0, QCPAxis* valueAxis = 0);
  2175. bool removeGraph(QCPGraph* graph);
  2176. bool removeGraph(int index);
  2177. int clearGraphs();
  2178. int graphCount() const;
  2179. QList<QCPGraph*> selectedGraphs() const;
  2180. // item interface:
  2181. QCPAbstractItem* item(int index) const;
  2182. QCPAbstractItem* item() const;
  2183. bool addItem(QCPAbstractItem* item);
  2184. bool removeItem(QCPAbstractItem* item);
  2185. bool removeItem(int index);
  2186. int clearItems();
  2187. int itemCount() const;
  2188. QList<QCPAbstractItem*> selectedItems() const;
  2189. QCPAbstractItem* itemAt(const QPointF& pos, bool onlySelectable = false) const;
  2190. bool hasItem(QCPAbstractItem* item) const;
  2191. // layer interface:
  2192. QCPLayer* layer(const QString& name) const;
  2193. QCPLayer* layer(int index) const;
  2194. QCPLayer* currentLayer() const;
  2195. bool setCurrentLayer(const QString& name);
  2196. bool setCurrentLayer(QCPLayer* layer);
  2197. int layerCount() const;
  2198. bool addLayer(const QString& name, QCPLayer* otherLayer = 0,
  2199. LayerInsertMode insertMode = limAbove);
  2200. bool removeLayer(QCPLayer* layer);
  2201. bool moveLayer(QCPLayer* layer, QCPLayer* otherLayer, LayerInsertMode insertMode = limAbove);
  2202. // axis rect/layout interface:
  2203. int axisRectCount() const;
  2204. QCPAxisRect* axisRect(int index = 0) const;
  2205. QList<QCPAxisRect*> axisRects() const;
  2206. QCPLayoutElement* layoutElementAt(const QPointF& pos) const;
  2207. Q_SLOT void rescaleAxes(bool onlyVisiblePlottables = false);
  2208. QList<QCPAxis*> selectedAxes() const;
  2209. QList<QCPLegend*> selectedLegends() const;
  2210. Q_SLOT void deselectAll();
  2211. bool savePdf(const QString& fileName, bool noCosmeticPen = false, int width = 0, int height = 0,
  2212. const QString& pdfCreator = QString(), const QString& pdfTitle = QString());
  2213. bool savePng(const QString& fileName, int width = 0, int height = 0, double scale = 1.0,
  2214. int quality = -1);
  2215. bool saveJpg(const QString& fileName, int width = 0, int height = 0, double scale = 1.0,
  2216. int quality = -1);
  2217. bool saveBmp(const QString& fileName, int width = 0, int height = 0, double scale = 1.0);
  2218. bool saveRastered(const QString& fileName, int width, int height, double scale,
  2219. const char* format, int quality = -1);
  2220. QPixmap toPixmap(int width = 0, int height = 0, double scale = 1.0);
  2221. void toPainter(QCPPainter* painter, int width = 0, int height = 0);
  2222. Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority = QCustomPlot::rpHint);
  2223. QCPAxis * xAxis, *yAxis, *xAxis2, *yAxis2;
  2224. QCPLegend* legend;
  2225. signals:
  2226. void mouseDoubleClick(QMouseEvent* event);
  2227. void mousePress(QMouseEvent* event);
  2228. void mouseMove(QMouseEvent* event);
  2229. void mouseRelease(QMouseEvent* event);
  2230. void mouseWheel(QWheelEvent* event);
  2231. void plottableClick(QCPAbstractPlottable* plottable, QMouseEvent* event);
  2232. void plottableDoubleClick(QCPAbstractPlottable* plottable, QMouseEvent* event);
  2233. void itemClick(QCPAbstractItem* item, QMouseEvent* event);
  2234. void itemDoubleClick(QCPAbstractItem* item, QMouseEvent* event);
  2235. void axisClick(QCPAxis* axis, QCPAxis::SelectablePart part, QMouseEvent* event);
  2236. void axisDoubleClick(QCPAxis* axis, QCPAxis::SelectablePart part, QMouseEvent* event);
  2237. void legendClick(QCPLegend* legend, QCPAbstractLegendItem* item, QMouseEvent* event);
  2238. void legendDoubleClick(QCPLegend* legend, QCPAbstractLegendItem* item, QMouseEvent* event);
  2239. void titleClick(QMouseEvent* event, QCPPlotTitle* title);
  2240. void titleDoubleClick(QMouseEvent* event, QCPPlotTitle* title);
  2241. void selectionChangedByUser();
  2242. void beforeReplot();
  2243. void afterReplot();
  2244. protected:
  2245. // property members:
  2246. QRect mViewport;
  2247. QCPLayoutGrid* mPlotLayout;
  2248. bool mAutoAddPlottableToLegend;
  2249. QList<QCPAbstractPlottable*> mPlottables;
  2250. QList<QCPGraph*>
  2251. mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph
  2252. QList<QCPAbstractItem*> mItems;
  2253. QList<QCPLayer*> mLayers;
  2254. QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements;
  2255. QCP::Interactions mInteractions;
  2256. int mSelectionTolerance;
  2257. bool mNoAntialiasingOnDrag;
  2258. QBrush mBackgroundBrush;
  2259. QPixmap mBackgroundPixmap;
  2260. QPixmap mScaledBackgroundPixmap;
  2261. bool mBackgroundScaled;
  2262. Qt::AspectRatioMode mBackgroundScaledMode;
  2263. QCPLayer* mCurrentLayer;
  2264. QCP::PlottingHints mPlottingHints;
  2265. Qt::KeyboardModifier mMultiSelectModifier;
  2266. // non-property members:
  2267. QPixmap mPaintBuffer;
  2268. QPoint mMousePressPos;
  2269. QPointer<QCPLayoutElement> mMouseEventElement;
  2270. bool mReplotting;
  2271. // reimplemented virtual methods:
  2272. virtual QSize minimumSizeHint() const;
  2273. virtual QSize sizeHint() const;
  2274. virtual void paintEvent(QPaintEvent* event);
  2275. virtual void resizeEvent(QResizeEvent* event);
  2276. virtual void mouseDoubleClickEvent(QMouseEvent* event);
  2277. virtual void mousePressEvent(QMouseEvent* event);
  2278. virtual void mouseMoveEvent(QMouseEvent* event);
  2279. virtual void mouseReleaseEvent(QMouseEvent* event);
  2280. virtual void wheelEvent(QWheelEvent* event);
  2281. // introduced virtual methods:
  2282. virtual void draw(QCPPainter* painter);
  2283. virtual void axisRemoved(QCPAxis* axis);
  2284. virtual void legendRemoved(QCPLegend* legend);
  2285. // non-virtual methods:
  2286. void updateLayerIndices() const;
  2287. QCPLayerable* layerableAt(const QPointF& pos, bool onlySelectable,
  2288. QVariant* selectionDetails = 0) const;
  2289. void drawBackground(QCPPainter* painter);
  2290. friend class QCPLegend;
  2291. friend class QCPAxis;
  2292. friend class QCPLayer;
  2293. friend class QCPAxisRect;
  2294. /*
  2295. //增加游标
  2296. public:
  2297. void showTracer(bool show)
  2298. {
  2299. m_isShowTracer = show;
  2300. if (m_xTracer)
  2301. m_xTracer->setVisible(m_isShowTracer);
  2302. foreach(XxwTracer * tracer, m_dataTracers)
  2303. {
  2304. if (tracer)
  2305. tracer->setVisible(m_isShowTracer);
  2306. }
  2307. if (m_lineTracer)
  2308. m_lineTracer->setVisible(m_isShowTracer);
  2309. }
  2310. private:
  2311. bool m_isShowTracer;//是否显示追踪器(鼠标在图中移动,显示对应的值)
  2312. XxwTracer* m_xTracer;//x轴
  2313. XxwTracer* m_yTracer;//y轴
  2314. QList<XxwTracer*> m_dataTracers;//
  2315. XxwTraceLine* m_lineTracer;//直线
  2316. */
  2317. };
  2318. class QCP_LIB_DECL QCPColorGradient
  2319. {
  2320. Q_GADGET
  2321. public:
  2322. /*!
  2323. Defines the color spaces in which color interpolation between gradient stops can be performed.
  2324. \see setColorInterpolation
  2325. */
  2326. enum ColorInterpolation {
  2327. ciRGB ///< Color channels red, green and blue are linearly interpolated
  2328. ,
  2329. ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is
  2330. ///< interpolated over the shortest angle distance)
  2331. };
  2332. Q_ENUMS(ColorInterpolation)
  2333. /*!
  2334. Defines the available presets that can be loaded with \ref loadPreset. See the documentation
  2335. there for an image of the presets.
  2336. */
  2337. enum GradientPreset {
  2338. gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data
  2339. ///< representation)
  2340. ,
  2341. gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased
  2342. ///< data representation)
  2343. ,
  2344. gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased
  2345. ///< data representation)
  2346. ,
  2347. gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for
  2348. ///< non-biased data representation)
  2349. ,
  2350. gpCandy ///< Blue over pink to white
  2351. ,
  2352. gpGeography ///< Colors suitable to represent different elevations on geographical maps
  2353. ,
  2354. gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates
  2355. ///< banding illusion but allows more precise magnitude estimates)
  2356. ,
  2357. gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to
  2358. ///< orange, yellow and white
  2359. ,
  2360. gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for
  2361. ///< negative, black in the middle and red for positive values
  2362. ,
  2363. gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but
  2364. ///< allows more precise magnitude estimates)
  2365. ,
  2366. gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization
  2367. ///< (creates banding illusion but allows more precise magnitude estimates)
  2368. ,
  2369. gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data,
  2370. ///< such as angles and phases, see \ref setPeriodic)
  2371. };
  2372. Q_ENUMS(GradientPreset)
  2373. QCPColorGradient(GradientPreset preset = gpCold);
  2374. bool operator==(const QCPColorGradient& other) const;
  2375. bool operator!=(const QCPColorGradient& other) const
  2376. {
  2377. return !(*this == other);
  2378. }
  2379. // getters:
  2380. int levelCount() const
  2381. {
  2382. return mLevelCount;
  2383. }
  2384. QMap<double, QColor> colorStops() const
  2385. {
  2386. return mColorStops;
  2387. }
  2388. ColorInterpolation colorInterpolation() const
  2389. {
  2390. return mColorInterpolation;
  2391. }
  2392. bool periodic() const
  2393. {
  2394. return mPeriodic;
  2395. }
  2396. // setters:
  2397. void setLevelCount(int n);
  2398. void setColorStops(const QMap<double, QColor>& colorStops);
  2399. void setColorStopAt(double position, const QColor& color);
  2400. void setColorInterpolation(ColorInterpolation interpolation);
  2401. void setPeriodic(bool enabled);
  2402. // non-property methods:
  2403. void colorize(const double* data, const QCPRange& range, QRgb* scanLine, int n,
  2404. int dataIndexFactor = 1, bool logarithmic = false);
  2405. QRgb color(double position, const QCPRange& range, bool logarithmic = false);
  2406. void loadPreset(GradientPreset preset);
  2407. void clearColorStops();
  2408. QCPColorGradient inverted() const;
  2409. protected:
  2410. void updateColorBuffer();
  2411. // property members:
  2412. int mLevelCount;
  2413. QMap<double, QColor> mColorStops;
  2414. ColorInterpolation mColorInterpolation;
  2415. bool mPeriodic;
  2416. // non-property members:
  2417. QVector<QRgb> mColorBuffer;
  2418. bool mColorBufferInvalidated;
  2419. };
  2420. class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement
  2421. {
  2422. Q_OBJECT
  2423. /// \cond INCLUDE_QPROPERTIES
  2424. Q_PROPERTY(QPixmap background READ background WRITE setBackground)
  2425. Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
  2426. Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE
  2427. setBackgroundScaledMode)
  2428. Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag)
  2429. Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom)
  2430. /// \endcond
  2431. public:
  2432. explicit QCPAxisRect(QCustomPlot* parentPlot, bool setupDefaultAxes = true);
  2433. virtual ~QCPAxisRect();
  2434. // getters:
  2435. QPixmap background() const
  2436. {
  2437. return mBackgroundPixmap;
  2438. }
  2439. bool backgroundScaled() const
  2440. {
  2441. return mBackgroundScaled;
  2442. }
  2443. Qt::AspectRatioMode backgroundScaledMode() const
  2444. {
  2445. return mBackgroundScaledMode;
  2446. }
  2447. Qt::Orientations rangeDrag() const
  2448. {
  2449. return mRangeDrag;
  2450. }
  2451. Qt::Orientations rangeZoom() const
  2452. {
  2453. return mRangeZoom;
  2454. }
  2455. QCPAxis* rangeDragAxis(Qt::Orientation orientation);
  2456. QCPAxis* rangeZoomAxis(Qt::Orientation orientation);
  2457. double rangeZoomFactor(Qt::Orientation orientation);
  2458. // setters:
  2459. void setBackground(const QPixmap& pm);
  2460. void setBackground(const QPixmap& pm, bool scaled,
  2461. Qt::AspectRatioMode mode = Qt::KeepAspectRatioByExpanding);
  2462. void setBackground(const QBrush& brush);
  2463. void setBackgroundScaled(bool scaled);
  2464. void setBackgroundScaledMode(Qt::AspectRatioMode mode);
  2465. void setRangeDrag(Qt::Orientations orientations);
  2466. void setRangeZoom(Qt::Orientations orientations);
  2467. void setRangeDragAxes(QCPAxis* horizontal, QCPAxis* vertical);
  2468. void setRangeZoomAxes(QCPAxis* horizontal, QCPAxis* vertical);
  2469. void setRangeZoomFactor(double horizontalFactor, double verticalFactor);
  2470. void setRangeZoomFactor(double factor);
  2471. // non-property methods:
  2472. int axisCount(QCPAxis::AxisType type) const;
  2473. QCPAxis* axis(QCPAxis::AxisType type, int index = 0) const;
  2474. QList<QCPAxis*> axes(QCPAxis::AxisTypes types) const;
  2475. QList<QCPAxis*> axes() const;
  2476. QCPAxis* addAxis(QCPAxis::AxisType type, QCPAxis* axis = 0);
  2477. QList<QCPAxis*> addAxes(QCPAxis::AxisTypes types);
  2478. bool removeAxis(QCPAxis* axis);
  2479. QCPLayoutInset* insetLayout() const
  2480. {
  2481. return mInsetLayout;
  2482. }
  2483. void setupFullAxesBox(bool connectRanges = false);
  2484. QList<QCPAbstractPlottable*> plottables() const;
  2485. QList<QCPGraph*> graphs() const;
  2486. QList<QCPAbstractItem*> items() const;
  2487. // read-only interface imitating a QRect:
  2488. int left() const
  2489. {
  2490. return mRect.left();
  2491. }
  2492. int right() const
  2493. {
  2494. return mRect.right();
  2495. }
  2496. int top() const
  2497. {
  2498. return mRect.top();
  2499. }
  2500. int bottom() const
  2501. {
  2502. return mRect.bottom();
  2503. }
  2504. int width() const
  2505. {
  2506. return mRect.width();
  2507. }
  2508. int height() const
  2509. {
  2510. return mRect.height();
  2511. }
  2512. QSize size() const
  2513. {
  2514. return mRect.size();
  2515. }
  2516. QPoint topLeft() const
  2517. {
  2518. return mRect.topLeft();
  2519. }
  2520. QPoint topRight() const
  2521. {
  2522. return mRect.topRight();
  2523. }
  2524. QPoint bottomLeft() const
  2525. {
  2526. return mRect.bottomLeft();
  2527. }
  2528. QPoint bottomRight() const
  2529. {
  2530. return mRect.bottomRight();
  2531. }
  2532. QPoint center() const
  2533. {
  2534. return mRect.center();
  2535. }
  2536. // reimplemented virtual methods:
  2537. virtual void update(UpdatePhase phase);
  2538. virtual QList<QCPLayoutElement*> elements(bool recursive) const;
  2539. protected:
  2540. // property members:
  2541. QBrush mBackgroundBrush;
  2542. QPixmap mBackgroundPixmap;
  2543. QPixmap mScaledBackgroundPixmap;
  2544. bool mBackgroundScaled;
  2545. Qt::AspectRatioMode mBackgroundScaledMode;
  2546. QCPLayoutInset* mInsetLayout;
  2547. Qt::Orientations mRangeDrag, mRangeZoom;
  2548. QPointer<QCPAxis> mRangeDragHorzAxis, mRangeDragVertAxis, mRangeZoomHorzAxis,
  2549. mRangeZoomVertAxis;
  2550. double mRangeZoomFactorHorz, mRangeZoomFactorVert;
  2551. // non-property members:
  2552. QCPRange mDragStartHorzRange, mDragStartVertRange;
  2553. QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
  2554. QPoint mDragStart;
  2555. bool mDragging;
  2556. QHash<QCPAxis::AxisType, QList<QCPAxis*>> mAxes;
  2557. // reimplemented virtual methods:
  2558. virtual void applyDefaultAntialiasingHint(QCPPainter* painter) const;
  2559. virtual void draw(QCPPainter* painter);
  2560. virtual int calculateAutoMargin(QCP::MarginSide side);
  2561. // events:
  2562. virtual void mousePressEvent(QMouseEvent* event);
  2563. virtual void mouseMoveEvent(QMouseEvent* event);
  2564. virtual void mouseReleaseEvent(QMouseEvent* event);
  2565. virtual void wheelEvent(QWheelEvent* event);
  2566. // non-property methods:
  2567. void drawBackground(QCPPainter* painter);
  2568. void updateAxesOffset(QCPAxis::AxisType type);
  2569. private:
  2570. Q_DISABLE_COPY(QCPAxisRect)
  2571. friend class QCustomPlot;
  2572. };
  2573. class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement
  2574. {
  2575. Q_OBJECT
  2576. /// \cond INCLUDE_QPROPERTIES
  2577. Q_PROPERTY(QCPLegend* parentLegend READ parentLegend)
  2578. Q_PROPERTY(QFont font READ font WRITE setFont)
  2579. Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
  2580. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  2581. Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
  2582. Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged)
  2583. Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged)
  2584. /// \endcond
  2585. public:
  2586. explicit QCPAbstractLegendItem(QCPLegend* parent);
  2587. // getters:
  2588. QCPLegend* parentLegend() const
  2589. {
  2590. return mParentLegend;
  2591. }
  2592. QFont font() const
  2593. {
  2594. return mFont;
  2595. }
  2596. QColor textColor() const
  2597. {
  2598. return mTextColor;
  2599. }
  2600. QFont selectedFont() const
  2601. {
  2602. return mSelectedFont;
  2603. }
  2604. QColor selectedTextColor() const
  2605. {
  2606. return mSelectedTextColor;
  2607. }
  2608. bool selectable() const
  2609. {
  2610. return mSelectable;
  2611. }
  2612. bool selected() const
  2613. {
  2614. return mSelected;
  2615. }
  2616. // setters:
  2617. void setFont(const QFont& font);
  2618. void setTextColor(const QColor& color);
  2619. void setSelectedFont(const QFont& font);
  2620. void setSelectedTextColor(const QColor& color);
  2621. Q_SLOT void setSelectable(bool selectable);
  2622. Q_SLOT void setSelected(bool selected);
  2623. // reimplemented virtual methods:
  2624. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  2625. signals:
  2626. void selectionChanged(bool selected);
  2627. void selectableChanged(bool selectable);
  2628. protected:
  2629. // property members:
  2630. QCPLegend* mParentLegend;
  2631. QFont mFont;
  2632. QColor mTextColor;
  2633. QFont mSelectedFont;
  2634. QColor mSelectedTextColor;
  2635. bool mSelectable, mSelected;
  2636. // reimplemented virtual methods:
  2637. virtual QCP::Interaction selectionCategory() const;
  2638. virtual void applyDefaultAntialiasingHint(QCPPainter* painter) const;
  2639. virtual QRect clipRect() const;
  2640. virtual void draw(QCPPainter* painter) = 0;
  2641. // events:
  2642. virtual void selectEvent(QMouseEvent* event, bool additive, const QVariant& details,
  2643. bool* selectionStateChanged);
  2644. virtual void deselectEvent(bool* selectionStateChanged);
  2645. private:
  2646. Q_DISABLE_COPY(QCPAbstractLegendItem)
  2647. friend class QCPLegend;
  2648. };
  2649. class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem
  2650. {
  2651. Q_OBJECT
  2652. public:
  2653. QCPPlottableLegendItem(QCPLegend* parent, QCPAbstractPlottable* plottable);
  2654. // getters:
  2655. QCPAbstractPlottable* plottable()
  2656. {
  2657. return mPlottable;
  2658. }
  2659. protected:
  2660. // property members:
  2661. QCPAbstractPlottable* mPlottable;
  2662. // reimplemented virtual methods:
  2663. virtual void draw(QCPPainter* painter);
  2664. virtual QSize minimumSizeHint() const;
  2665. // non-virtual methods:
  2666. QPen getIconBorderPen() const;
  2667. QColor getTextColor() const;
  2668. QFont getFont() const;
  2669. };
  2670. class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid
  2671. {
  2672. Q_OBJECT
  2673. /// \cond INCLUDE_QPROPERTIES
  2674. Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen)
  2675. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  2676. Q_PROPERTY(QFont font READ font WRITE setFont)
  2677. Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
  2678. Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
  2679. Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding)
  2680. Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen)
  2681. Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY
  2682. selectionChanged)
  2683. Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY
  2684. selectableChanged)
  2685. Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen)
  2686. Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen)
  2687. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  2688. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  2689. Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
  2690. /// \endcond
  2691. public:
  2692. /*!
  2693. Defines the selectable parts of a legend
  2694. \see setSelectedParts, setSelectableParts
  2695. */
  2696. enum SelectablePart {
  2697. spNone = 0x000 ///< <tt>0x000</tt> None
  2698. ,
  2699. spLegendBox = 0x001 ///< <tt>0x001</tt> The legend box (frame)
  2700. ,
  2701. spItems = 0x002 ///< <tt>0x002</tt> Legend items individually (see \ref selectedItems)
  2702. };
  2703. Q_FLAGS(SelectablePart SelectableParts)
  2704. Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
  2705. explicit QCPLegend();
  2706. virtual ~QCPLegend();
  2707. // getters:
  2708. QPen borderPen() const
  2709. {
  2710. return mBorderPen;
  2711. }
  2712. QBrush brush() const
  2713. {
  2714. return mBrush;
  2715. }
  2716. QFont font() const
  2717. {
  2718. return mFont;
  2719. }
  2720. QColor textColor() const
  2721. {
  2722. return mTextColor;
  2723. }
  2724. QSize iconSize() const
  2725. {
  2726. return mIconSize;
  2727. }
  2728. int iconTextPadding() const
  2729. {
  2730. return mIconTextPadding;
  2731. }
  2732. QPen iconBorderPen() const
  2733. {
  2734. return mIconBorderPen;
  2735. }
  2736. SelectableParts selectableParts() const
  2737. {
  2738. return mSelectableParts;
  2739. }
  2740. SelectableParts selectedParts() const;
  2741. QPen selectedBorderPen() const
  2742. {
  2743. return mSelectedBorderPen;
  2744. }
  2745. QPen selectedIconBorderPen() const
  2746. {
  2747. return mSelectedIconBorderPen;
  2748. }
  2749. QBrush selectedBrush() const
  2750. {
  2751. return mSelectedBrush;
  2752. }
  2753. QFont selectedFont() const
  2754. {
  2755. return mSelectedFont;
  2756. }
  2757. QColor selectedTextColor() const
  2758. {
  2759. return mSelectedTextColor;
  2760. }
  2761. // setters:
  2762. void setBorderPen(const QPen& pen);
  2763. void setBrush(const QBrush& brush);
  2764. void setFont(const QFont& font);
  2765. void setTextColor(const QColor& color);
  2766. void setIconSize(const QSize& size);
  2767. void setIconSize(int width, int height);
  2768. void setIconTextPadding(int padding);
  2769. void setIconBorderPen(const QPen& pen);
  2770. Q_SLOT void setSelectableParts(const SelectableParts& selectableParts);
  2771. Q_SLOT void setSelectedParts(const SelectableParts& selectedParts);
  2772. void setSelectedBorderPen(const QPen& pen);
  2773. void setSelectedIconBorderPen(const QPen& pen);
  2774. void setSelectedBrush(const QBrush& brush);
  2775. void setSelectedFont(const QFont& font);
  2776. void setSelectedTextColor(const QColor& color);
  2777. // reimplemented virtual methods:
  2778. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  2779. // non-virtual methods:
  2780. QCPAbstractLegendItem* item(int index) const;
  2781. QCPPlottableLegendItem* itemWithPlottable(const QCPAbstractPlottable* plottable) const;
  2782. int itemCount() const;
  2783. bool hasItem(QCPAbstractLegendItem* item) const;
  2784. bool hasItemWithPlottable(const QCPAbstractPlottable* plottable) const;
  2785. bool addItem(QCPAbstractLegendItem* item);
  2786. bool removeItem(int index);
  2787. bool removeItem(QCPAbstractLegendItem* item);
  2788. void clearItems();
  2789. QList<QCPAbstractLegendItem*> selectedItems() const;
  2790. signals:
  2791. void selectionChanged(QCPLegend::SelectableParts parts);
  2792. void selectableChanged(QCPLegend::SelectableParts parts);
  2793. protected:
  2794. // property members:
  2795. QPen mBorderPen, mIconBorderPen;
  2796. QBrush mBrush;
  2797. QFont mFont;
  2798. QColor mTextColor;
  2799. QSize mIconSize;
  2800. int mIconTextPadding;
  2801. SelectableParts mSelectedParts, mSelectableParts;
  2802. QPen mSelectedBorderPen, mSelectedIconBorderPen;
  2803. QBrush mSelectedBrush;
  2804. QFont mSelectedFont;
  2805. QColor mSelectedTextColor;
  2806. // reimplemented virtual methods:
  2807. virtual void parentPlotInitialized(QCustomPlot* parentPlot);
  2808. virtual QCP::Interaction selectionCategory() const;
  2809. virtual void applyDefaultAntialiasingHint(QCPPainter* painter) const;
  2810. virtual void draw(QCPPainter* painter);
  2811. // events:
  2812. virtual void selectEvent(QMouseEvent* event, bool additive, const QVariant& details,
  2813. bool* selectionStateChanged);
  2814. virtual void deselectEvent(bool* selectionStateChanged);
  2815. // non-virtual methods:
  2816. QPen getBorderPen() const;
  2817. QBrush getBrush() const;
  2818. private:
  2819. Q_DISABLE_COPY(QCPLegend)
  2820. friend class QCustomPlot;
  2821. friend class QCPAbstractLegendItem;
  2822. };
  2823. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts)
  2824. Q_DECLARE_METATYPE(QCPLegend::SelectablePart)
  2825. class QCP_LIB_DECL QCPPlotTitle : public QCPLayoutElement
  2826. {
  2827. Q_OBJECT
  2828. /// \cond INCLUDE_QPROPERTIES
  2829. Q_PROPERTY(QString text READ text WRITE setText)
  2830. Q_PROPERTY(QFont font READ font WRITE setFont)
  2831. Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
  2832. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  2833. Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
  2834. Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
  2835. Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
  2836. /// \endcond
  2837. public:
  2838. explicit QCPPlotTitle(QCustomPlot* parentPlot);
  2839. explicit QCPPlotTitle(QCustomPlot* parentPlot, const QString& text);
  2840. // getters:
  2841. QString text() const
  2842. {
  2843. return mText;
  2844. }
  2845. QFont font() const
  2846. {
  2847. return mFont;
  2848. }
  2849. QColor textColor() const
  2850. {
  2851. return mTextColor;
  2852. }
  2853. QFont selectedFont() const
  2854. {
  2855. return mSelectedFont;
  2856. }
  2857. QColor selectedTextColor() const
  2858. {
  2859. return mSelectedTextColor;
  2860. }
  2861. bool selectable() const
  2862. {
  2863. return mSelectable;
  2864. }
  2865. bool selected() const
  2866. {
  2867. return mSelected;
  2868. }
  2869. // setters:
  2870. void setText(const QString& text);
  2871. void setFont(const QFont& font);
  2872. void setTextColor(const QColor& color);
  2873. void setSelectedFont(const QFont& font);
  2874. void setSelectedTextColor(const QColor& color);
  2875. Q_SLOT void setSelectable(bool selectable);
  2876. Q_SLOT void setSelected(bool selected);
  2877. // reimplemented virtual methods:
  2878. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  2879. signals:
  2880. void selectionChanged(bool selected);
  2881. void selectableChanged(bool selectable);
  2882. protected:
  2883. // property members:
  2884. QString mText;
  2885. QFont mFont;
  2886. QColor mTextColor;
  2887. QFont mSelectedFont;
  2888. QColor mSelectedTextColor;
  2889. QRect mTextBoundingRect;
  2890. bool mSelectable, mSelected;
  2891. // reimplemented virtual methods:
  2892. virtual void applyDefaultAntialiasingHint(QCPPainter* painter) const;
  2893. virtual void draw(QCPPainter* painter);
  2894. virtual QSize minimumSizeHint() const;
  2895. virtual QSize maximumSizeHint() const;
  2896. // events:
  2897. virtual void selectEvent(QMouseEvent* event, bool additive, const QVariant& details,
  2898. bool* selectionStateChanged);
  2899. virtual void deselectEvent(bool* selectionStateChanged);
  2900. // non-virtual methods:
  2901. QFont mainFont() const;
  2902. QColor mainTextColor() const;
  2903. private:
  2904. Q_DISABLE_COPY(QCPPlotTitle)
  2905. };
  2906. class QCPColorScaleAxisRectPrivate : public QCPAxisRect
  2907. {
  2908. Q_OBJECT
  2909. public:
  2910. explicit QCPColorScaleAxisRectPrivate(QCPColorScale* parentColorScale);
  2911. protected:
  2912. QCPColorScale* mParentColorScale;
  2913. QImage mGradientImage;
  2914. bool mGradientImageInvalidated;
  2915. // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale
  2916. using QCPAxisRect::calculateAutoMargin;
  2917. using QCPAxisRect::mouseMoveEvent;
  2918. using QCPAxisRect::mousePressEvent;
  2919. using QCPAxisRect::mouseReleaseEvent;
  2920. using QCPAxisRect::update;
  2921. using QCPAxisRect::wheelEvent;
  2922. virtual void draw(QCPPainter* painter);
  2923. void updateGradientImage();
  2924. Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts);
  2925. Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts);
  2926. friend class QCPColorScale;
  2927. };
  2928. class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement
  2929. {
  2930. Q_OBJECT
  2931. /// \cond INCLUDE_QPROPERTIES
  2932. Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType)
  2933. Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
  2934. Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY
  2935. dataScaleTypeChanged)
  2936. Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
  2937. Q_PROPERTY(QString label READ label WRITE setLabel)
  2938. Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth)
  2939. Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag)
  2940. Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom)
  2941. /// \endcond
  2942. public:
  2943. explicit QCPColorScale(QCustomPlot* parentPlot);
  2944. virtual ~QCPColorScale();
  2945. // getters:
  2946. QCPAxis* axis() const
  2947. {
  2948. return mColorAxis.data();
  2949. }
  2950. QCPAxis::AxisType type() const
  2951. {
  2952. return mType;
  2953. }
  2954. QCPRange dataRange() const
  2955. {
  2956. return mDataRange;
  2957. }
  2958. QCPAxis::ScaleType dataScaleType() const
  2959. {
  2960. return mDataScaleType;
  2961. }
  2962. QCPColorGradient gradient() const
  2963. {
  2964. return mGradient;
  2965. }
  2966. QString label() const;
  2967. int barWidth() const
  2968. {
  2969. return mBarWidth;
  2970. }
  2971. bool rangeDrag() const;
  2972. bool rangeZoom() const;
  2973. // setters:
  2974. void setType(QCPAxis::AxisType type);
  2975. Q_SLOT void setDataRange(const QCPRange& dataRange);
  2976. Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
  2977. Q_SLOT void setGradient(const QCPColorGradient& gradient);
  2978. void setLabel(const QString& str);
  2979. void setBarWidth(int width);
  2980. void setRangeDrag(bool enabled);
  2981. void setRangeZoom(bool enabled);
  2982. // non-property methods:
  2983. QList<QCPColorMap*> colorMaps() const;
  2984. void rescaleDataRange(bool onlyVisibleMaps);
  2985. // reimplemented virtual methods:
  2986. virtual void update(UpdatePhase phase);
  2987. signals:
  2988. void dataRangeChanged(QCPRange newRange);
  2989. void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
  2990. void gradientChanged(QCPColorGradient newGradient);
  2991. protected:
  2992. // property members:
  2993. QCPAxis::AxisType mType;
  2994. QCPRange mDataRange;
  2995. QCPAxis::ScaleType mDataScaleType;
  2996. QCPColorGradient mGradient;
  2997. int mBarWidth;
  2998. // non-property members:
  2999. QPointer<QCPColorScaleAxisRectPrivate> mAxisRect;
  3000. QPointer<QCPAxis> mColorAxis;
  3001. // reimplemented virtual methods:
  3002. virtual void applyDefaultAntialiasingHint(QCPPainter* painter) const;
  3003. // events:
  3004. virtual void mousePressEvent(QMouseEvent* event);
  3005. virtual void mouseMoveEvent(QMouseEvent* event);
  3006. virtual void mouseReleaseEvent(QMouseEvent* event);
  3007. virtual void wheelEvent(QWheelEvent* event);
  3008. private:
  3009. Q_DISABLE_COPY(QCPColorScale)
  3010. friend class QCPColorScaleAxisRectPrivate;
  3011. };
  3012. /*! \file */
  3013. class QCP_LIB_DECL QCPData
  3014. {
  3015. public:
  3016. QCPData();
  3017. QCPData(double key, double value);
  3018. double key, value;
  3019. double keyErrorPlus, keyErrorMinus;
  3020. double valueErrorPlus, valueErrorMinus;
  3021. };
  3022. Q_DECLARE_TYPEINFO(QCPData, Q_MOVABLE_TYPE);
  3023. /*! \typedef QCPDataMap
  3024. Container for storing \ref QCPData items in a sorted fashion. The key of the map
  3025. is the key member of the QCPData instance.
  3026. This is the container in which QCPGraph holds its data.
  3027. \see QCPData, QCPGraph::setData
  3028. */
  3029. typedef QMap<double, QCPData> QCPDataMap;
  3030. typedef QMapIterator<double, QCPData> QCPDataMapIterator;
  3031. typedef QMutableMapIterator<double, QCPData> QCPDataMutableMapIterator;
  3032. class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable
  3033. {
  3034. Q_OBJECT
  3035. /// \cond INCLUDE_QPROPERTIES
  3036. Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
  3037. Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
  3038. Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType)
  3039. Q_PROPERTY(QPen errorPen READ errorPen WRITE setErrorPen)
  3040. Q_PROPERTY(double errorBarSize READ errorBarSize WRITE setErrorBarSize)
  3041. Q_PROPERTY(bool errorBarSkipSymbol READ errorBarSkipSymbol WRITE setErrorBarSkipSymbol)
  3042. Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph)
  3043. Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling)
  3044. /// \endcond
  3045. public:
  3046. /*!
  3047. Defines how the graph's line is represented visually in the plot. The line is drawn with the
  3048. current pen of the graph (\ref setPen).
  3049. \see setLineStyle
  3050. */
  3051. enum LineStyle {
  3052. lsNone ///< data points are not connected with any lines (e.g. data only represented
  3053. ///< with symbols according to the scatter style, see \ref setScatterStyle)
  3054. ,
  3055. lsLine ///< data points are connected by a straight line
  3056. ,
  3057. lsStepLeft ///< line is drawn as steps where the step height is the value of the left data
  3058. ///< point
  3059. ,
  3060. lsStepRight ///< line is drawn as steps where the step height is the value of the right data
  3061. ///< point
  3062. ,
  3063. lsStepCenter ///< line is drawn as steps where the step is in between two data points
  3064. ,
  3065. lsImpulse ///< each data point is represented by a line parallel to the value axis, which
  3066. ///< reaches from the data point to the zero-value-line
  3067. };
  3068. Q_ENUMS(LineStyle)
  3069. /*!
  3070. Defines what kind of error bars are drawn for each data point
  3071. */
  3072. enum ErrorType {
  3073. etNone ///< No error bars are shown
  3074. ,
  3075. etKey ///< Error bars for the key dimension of the data point are shown
  3076. ,
  3077. etValue ///< Error bars for the value dimension of the data point are shown
  3078. ,
  3079. etBoth ///< Error bars for both key and value dimensions of the data point are shown
  3080. };
  3081. Q_ENUMS(ErrorType)
  3082. explicit QCPGraph(QCPAxis* keyAxis, QCPAxis* valueAxis);
  3083. virtual ~QCPGraph();
  3084. // getters:
  3085. QCPDataMap* data() const
  3086. {
  3087. return mData;
  3088. }
  3089. LineStyle lineStyle() const
  3090. {
  3091. return mLineStyle;
  3092. }
  3093. QCPScatterStyle scatterStyle() const
  3094. {
  3095. return mScatterStyle;
  3096. }
  3097. ErrorType errorType() const
  3098. {
  3099. return mErrorType;
  3100. }
  3101. QPen errorPen() const
  3102. {
  3103. return mErrorPen;
  3104. }
  3105. double errorBarSize() const
  3106. {
  3107. return mErrorBarSize;
  3108. }
  3109. bool errorBarSkipSymbol() const
  3110. {
  3111. return mErrorBarSkipSymbol;
  3112. }
  3113. QCPGraph* channelFillGraph() const
  3114. {
  3115. return mChannelFillGraph.data();
  3116. }
  3117. bool adaptiveSampling() const
  3118. {
  3119. return mAdaptiveSampling;
  3120. }
  3121. // setters:
  3122. void setData(QCPDataMap* data, bool copy = false);
  3123. void setData(const QVector<double>& key, const QVector<double>& value);
  3124. void setDataKeyError(const QVector<double>& key, const QVector<double>& value,
  3125. const QVector<double>& keyError);
  3126. void setDataKeyError(const QVector<double>& key, const QVector<double>& value,
  3127. const QVector<double>& keyErrorMinus, const QVector<double>& keyErrorPlus);
  3128. void setDataValueError(const QVector<double>& key, const QVector<double>& value,
  3129. const QVector<double>& valueError);
  3130. void setDataValueError(const QVector<double>& key, const QVector<double>& value,
  3131. const QVector<double>& valueErrorMinus,
  3132. const QVector<double>& valueErrorPlus);
  3133. void setDataBothError(const QVector<double>& key, const QVector<double>& value,
  3134. const QVector<double>& keyError, const QVector<double>& valueError);
  3135. void setDataBothError(const QVector<double>& key, const QVector<double>& value,
  3136. const QVector<double>& keyErrorMinus, const QVector<double>& keyErrorPlus,
  3137. const QVector<double>& valueErrorMinus,
  3138. const QVector<double>& valueErrorPlus);
  3139. void setLineStyle(LineStyle ls);
  3140. void setScatterStyle(const QCPScatterStyle& style);
  3141. void setErrorType(ErrorType errorType);
  3142. void setErrorPen(const QPen& pen);
  3143. void setErrorBarSize(double size);
  3144. void setErrorBarSkipSymbol(bool enabled);
  3145. void setChannelFillGraph(QCPGraph* targetGraph);
  3146. void setAdaptiveSampling(bool enabled);
  3147. // non-property methods:
  3148. void addData(const QCPDataMap& dataMap);
  3149. void addData(const QCPData& data);
  3150. void addData(double key, double value);
  3151. void addData(const QVector<double>& keys, const QVector<double>& values);
  3152. void removeDataBefore(double key);
  3153. void removeDataAfter(double key);
  3154. void removeData(double fromKey, double toKey);
  3155. void removeData(double key);
  3156. // reimplemented virtual methods:
  3157. virtual void clearData();
  3158. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  3159. using QCPAbstractPlottable::rescaleAxes;
  3160. using QCPAbstractPlottable::rescaleKeyAxis;
  3161. using QCPAbstractPlottable::rescaleValueAxis;
  3162. void rescaleAxes(bool onlyEnlarge,
  3163. bool includeErrorBars) const; // overloads base class interface
  3164. void rescaleKeyAxis(bool onlyEnlarge,
  3165. bool includeErrorBars) const; // overloads base class interface
  3166. void rescaleValueAxis(bool onlyEnlarge,
  3167. bool includeErrorBars) const; // overloads base class interface
  3168. protected:
  3169. // property members:
  3170. QCPDataMap* mData;
  3171. QPen mErrorPen;
  3172. LineStyle mLineStyle;
  3173. QCPScatterStyle mScatterStyle;
  3174. ErrorType mErrorType;
  3175. double mErrorBarSize;
  3176. bool mErrorBarSkipSymbol;
  3177. QPointer<QCPGraph> mChannelFillGraph;
  3178. bool mAdaptiveSampling;
  3179. // reimplemented virtual methods:
  3180. virtual void draw(QCPPainter* painter);
  3181. virtual void drawLegendIcon(QCPPainter* painter, const QRectF& rect) const;
  3182. virtual QCPRange getKeyRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3183. virtual QCPRange getValueRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3184. virtual QCPRange getKeyRange(bool& foundRange, SignDomain inSignDomain,
  3185. bool includeErrors) const; // overloads base class interface
  3186. virtual QCPRange getValueRange(bool& foundRange, SignDomain inSignDomain,
  3187. bool includeErrors) const; // overloads base class interface
  3188. // introduced virtual methods:
  3189. virtual void drawFill(QCPPainter* painter, QVector<QPointF>* lineData) const;
  3190. virtual void drawScatterPlot(QCPPainter* painter, QVector<QCPData>* scatterData) const;
  3191. virtual void drawLinePlot(QCPPainter* painter, QVector<QPointF>* lineData) const;
  3192. virtual void drawImpulsePlot(QCPPainter* painter, QVector<QPointF>* lineData) const;
  3193. // non-virtual methods:
  3194. void getPreparedData(QVector<QCPData>* lineData, QVector<QCPData>* scatterData) const;
  3195. void getPlotData(QVector<QPointF>* lineData, QVector<QCPData>* scatterData) const;
  3196. void getScatterPlotData(QVector<QCPData>* scatterData) const;
  3197. void getLinePlotData(QVector<QPointF>* linePixelData, QVector<QCPData>* scatterData) const;
  3198. void getStepLeftPlotData(QVector<QPointF>* linePixelData, QVector<QCPData>* scatterData) const;
  3199. void getStepRightPlotData(QVector<QPointF>* linePixelData, QVector<QCPData>* scatterData) const;
  3200. void getStepCenterPlotData(QVector<QPointF>* linePixelData,
  3201. QVector<QCPData>* scatterData) const;
  3202. void getImpulsePlotData(QVector<QPointF>* linePixelData, QVector<QCPData>* scatterData) const;
  3203. void drawError(QCPPainter* painter, double x, double y, const QCPData& data) const;
  3204. void getVisibleDataBounds(QCPDataMap::const_iterator& lower,
  3205. QCPDataMap::const_iterator& upper) const;
  3206. int countDataInBounds(const QCPDataMap::const_iterator& lower,
  3207. const QCPDataMap::const_iterator& upper, int maxCount) const;
  3208. void addFillBasePoints(QVector<QPointF>* lineData) const;
  3209. void removeFillBasePoints(QVector<QPointF>* lineData) const;
  3210. QPointF lowerFillBasePoint(double lowerKey) const;
  3211. QPointF upperFillBasePoint(double upperKey) const;
  3212. const QPolygonF getChannelFillPolygon(const QVector<QPointF>* lineData) const;
  3213. int findIndexBelowX(const QVector<QPointF>* data, double x) const;
  3214. int findIndexAboveX(const QVector<QPointF>* data, double x) const;
  3215. int findIndexBelowY(const QVector<QPointF>* data, double y) const;
  3216. int findIndexAboveY(const QVector<QPointF>* data, double y) const;
  3217. double pointDistance(const QPointF& pixelPoint) const;
  3218. friend class QCustomPlot;
  3219. friend class QCPLegend;
  3220. };
  3221. /*! \file */
  3222. class QCP_LIB_DECL QCPCurveData
  3223. {
  3224. public:
  3225. QCPCurveData();
  3226. QCPCurveData(double t, double key, double value);
  3227. double t, key, value;
  3228. };
  3229. Q_DECLARE_TYPEINFO(QCPCurveData, Q_MOVABLE_TYPE);
  3230. /*! \typedef QCPCurveDataMap
  3231. Container for storing \ref QCPCurveData items in a sorted fashion. The key of the map
  3232. is the t member of the QCPCurveData instance.
  3233. This is the container in which QCPCurve holds its data.
  3234. \see QCPCurveData, QCPCurve::setData
  3235. */
  3236. typedef QMap<double, QCPCurveData> QCPCurveDataMap;
  3237. typedef QMapIterator<double, QCPCurveData> QCPCurveDataMapIterator;
  3238. typedef QMutableMapIterator<double, QCPCurveData> QCPCurveDataMutableMapIterator;
  3239. class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable
  3240. {
  3241. Q_OBJECT
  3242. /// \cond INCLUDE_QPROPERTIES
  3243. Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
  3244. Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
  3245. /// \endcond
  3246. public:
  3247. /*!
  3248. Defines how the curve's line is represented visually in the plot. The line is drawn with the
  3249. current pen of the curve (\ref setPen).
  3250. \see setLineStyle
  3251. */
  3252. enum LineStyle {
  3253. lsNone ///< No line is drawn between data points (e.g. only scatters)
  3254. ,
  3255. lsLine ///< Data points are connected with a straight line
  3256. };
  3257. explicit QCPCurve(QCPAxis* keyAxis, QCPAxis* valueAxis);
  3258. virtual ~QCPCurve();
  3259. // getters:
  3260. QCPCurveDataMap* data() const
  3261. {
  3262. return mData;
  3263. }
  3264. QCPScatterStyle scatterStyle() const
  3265. {
  3266. return mScatterStyle;
  3267. }
  3268. LineStyle lineStyle() const
  3269. {
  3270. return mLineStyle;
  3271. }
  3272. // setters:
  3273. void setData(QCPCurveDataMap* data, bool copy = false);
  3274. void setData(const QVector<double>& t, const QVector<double>& key,
  3275. const QVector<double>& value);
  3276. void setData(const QVector<double>& key, const QVector<double>& value);
  3277. void setScatterStyle(const QCPScatterStyle& style);
  3278. void setLineStyle(LineStyle style);
  3279. // non-property methods:
  3280. void addData(const QCPCurveDataMap& dataMap);
  3281. void addData(const QCPCurveData& data);
  3282. void addData(double t, double key, double value);
  3283. void addData(double key, double value);
  3284. void addData(const QVector<double>& ts, const QVector<double>& keys,
  3285. const QVector<double>& values);
  3286. void removeDataBefore(double t);
  3287. void removeDataAfter(double t);
  3288. void removeData(double fromt, double tot);
  3289. void removeData(double t);
  3290. // reimplemented virtual methods:
  3291. virtual void clearData();
  3292. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  3293. protected:
  3294. // property members:
  3295. QCPCurveDataMap* mData;
  3296. QCPScatterStyle mScatterStyle;
  3297. LineStyle mLineStyle;
  3298. // reimplemented virtual methods:
  3299. virtual void draw(QCPPainter* painter);
  3300. virtual void drawLegendIcon(QCPPainter* painter, const QRectF& rect) const;
  3301. virtual QCPRange getKeyRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3302. virtual QCPRange getValueRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3303. // introduced virtual methods:
  3304. virtual void drawScatterPlot(QCPPainter* painter, const QVector<QPointF>* pointData) const;
  3305. // non-virtual methods:
  3306. void getCurveData(QVector<QPointF>* lineData) const;
  3307. int getRegion(double x, double y, double rectLeft, double rectTop, double rectRight,
  3308. double rectBottom) const;
  3309. QPointF getOptimizedPoint(int prevRegion, double prevKey, double prevValue, double key,
  3310. double value, double rectLeft, double rectTop, double rectRight,
  3311. double rectBottom) const;
  3312. QVector<QPointF> getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey,
  3313. double prevValue, double key, double value,
  3314. double rectLeft, double rectTop, double rectRight,
  3315. double rectBottom) const;
  3316. bool mayTraverse(int prevRegion, int currentRegion) const;
  3317. bool getTraverse(double prevKey, double prevValue, double key, double value, double rectLeft,
  3318. double rectTop, double rectRight, double rectBottom, QPointF& crossA,
  3319. QPointF& crossB) const;
  3320. void getTraverseCornerPoints(int prevRegion, int currentRegion, double rectLeft, double rectTop,
  3321. double rectRight, double rectBottom,
  3322. QVector<QPointF>& beforeTraverse,
  3323. QVector<QPointF>& afterTraverse) const;
  3324. double pointDistance(const QPointF& pixelPoint) const;
  3325. friend class QCustomPlot;
  3326. friend class QCPLegend;
  3327. };
  3328. /*! \file */
  3329. class QCP_LIB_DECL QCPBarsGroup : public QObject
  3330. {
  3331. Q_OBJECT
  3332. /// \cond INCLUDE_QPROPERTIES
  3333. Q_PROPERTY(SpacingType spacingType READ spacingType WRITE setSpacingType)
  3334. Q_PROPERTY(double spacing READ spacing WRITE setSpacing)
  3335. /// \endcond
  3336. public:
  3337. /*!
  3338. Defines the ways the spacing between bars in the group can be specified. Thus it defines what
  3339. the number passed to \ref setSpacing actually means.
  3340. \see setSpacingType, setSpacing
  3341. */
  3342. enum SpacingType {
  3343. stAbsolute ///< Bar spacing is in absolute pixels
  3344. ,
  3345. stAxisRectRatio ///< Bar spacing is given by a fraction of the axis rect size
  3346. ,
  3347. stPlotCoords ///< Bar spacing is in key coordinates and thus scales with the key axis range
  3348. };
  3349. QCPBarsGroup(QCustomPlot* parentPlot);
  3350. ~QCPBarsGroup();
  3351. // getters:
  3352. SpacingType spacingType() const
  3353. {
  3354. return mSpacingType;
  3355. }
  3356. double spacing() const
  3357. {
  3358. return mSpacing;
  3359. }
  3360. // setters:
  3361. void setSpacingType(SpacingType spacingType);
  3362. void setSpacing(double spacing);
  3363. // non-virtual methods:
  3364. QList<QCPBars*> bars() const
  3365. {
  3366. return mBars;
  3367. }
  3368. QCPBars* bars(int index) const;
  3369. int size() const
  3370. {
  3371. return mBars.size();
  3372. }
  3373. bool isEmpty() const
  3374. {
  3375. return mBars.isEmpty();
  3376. }
  3377. void clear();
  3378. bool contains(QCPBars* bars) const
  3379. {
  3380. return mBars.contains(bars);
  3381. }
  3382. void append(QCPBars* bars);
  3383. void insert(int i, QCPBars* bars);
  3384. void remove(QCPBars* bars);
  3385. protected:
  3386. // non-property members:
  3387. QCustomPlot* mParentPlot;
  3388. SpacingType mSpacingType;
  3389. double mSpacing;
  3390. QList<QCPBars*> mBars;
  3391. // non-virtual methods:
  3392. void registerBars(QCPBars* bars);
  3393. void unregisterBars(QCPBars* bars);
  3394. // virtual methods:
  3395. double keyPixelOffset(const QCPBars* bars, double keyCoord);
  3396. double getPixelSpacing(const QCPBars* bars, double keyCoord);
  3397. private:
  3398. Q_DISABLE_COPY(QCPBarsGroup)
  3399. friend class QCPBars;
  3400. };
  3401. class QCP_LIB_DECL QCPBarData
  3402. {
  3403. public:
  3404. QCPBarData();
  3405. QCPBarData(double key, double value);
  3406. double key, value;
  3407. };
  3408. Q_DECLARE_TYPEINFO(QCPBarData, Q_MOVABLE_TYPE);
  3409. /*! \typedef QCPBarDataMap
  3410. Container for storing \ref QCPBarData items in a sorted fashion. The key of the map
  3411. is the key member of the QCPBarData instance.
  3412. This is the container in which QCPBars holds its data.
  3413. \see QCPBarData, QCPBars::setData
  3414. */
  3415. typedef QMap<double, QCPBarData> QCPBarDataMap;
  3416. typedef QMapIterator<double, QCPBarData> QCPBarDataMapIterator;
  3417. typedef QMutableMapIterator<double, QCPBarData> QCPBarDataMutableMapIterator;
  3418. class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable
  3419. {
  3420. Q_OBJECT
  3421. /// \cond INCLUDE_QPROPERTIES
  3422. Q_PROPERTY(double width READ width WRITE setWidth)
  3423. Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType)
  3424. Q_PROPERTY(QCPBarsGroup* barsGroup READ barsGroup WRITE setBarsGroup)
  3425. Q_PROPERTY(double baseValue READ baseValue WRITE setBaseValue)
  3426. Q_PROPERTY(QCPBars* barBelow READ barBelow)
  3427. Q_PROPERTY(QCPBars* barAbove READ barAbove)
  3428. /// \endcond
  3429. public:
  3430. /*!
  3431. Defines the ways the width of the bar can be specified. Thus it defines what the number passed
  3432. to \ref setWidth actually means.
  3433. \see setWidthType, setWidth
  3434. */
  3435. enum WidthType {
  3436. wtAbsolute ///< Bar width is in absolute pixels
  3437. ,
  3438. wtAxisRectRatio ///< Bar width is given by a fraction of the axis rect size
  3439. ,
  3440. wtPlotCoords ///< Bar width is in key coordinates and thus scales with the key axis range
  3441. };
  3442. Q_ENUMS(WidthType)
  3443. explicit QCPBars(QCPAxis* keyAxis, QCPAxis* valueAxis);
  3444. virtual ~QCPBars();
  3445. // getters:
  3446. double width() const
  3447. {
  3448. return mWidth;
  3449. }
  3450. WidthType widthType() const
  3451. {
  3452. return mWidthType;
  3453. }
  3454. QCPBarsGroup* barsGroup() const
  3455. {
  3456. return mBarsGroup;
  3457. }
  3458. double baseValue() const
  3459. {
  3460. return mBaseValue;
  3461. }
  3462. QCPBars* barBelow() const
  3463. {
  3464. return mBarBelow.data();
  3465. }
  3466. QCPBars* barAbove() const
  3467. {
  3468. return mBarAbove.data();
  3469. }
  3470. QCPBarDataMap* data() const
  3471. {
  3472. return mData;
  3473. }
  3474. // setters:
  3475. void setWidth(double width);
  3476. void setWidthType(WidthType widthType);
  3477. void setBarsGroup(QCPBarsGroup* barsGroup);
  3478. void setBaseValue(double baseValue);
  3479. void setData(QCPBarDataMap* data, bool copy = false);
  3480. void setData(const QVector<double>& key, const QVector<double>& value);
  3481. // non-property methods:
  3482. void moveBelow(QCPBars* bars);
  3483. void moveAbove(QCPBars* bars);
  3484. void addData(const QCPBarDataMap& dataMap);
  3485. void addData(const QCPBarData& data);
  3486. void addData(double key, double value);
  3487. void addData(const QVector<double>& keys, const QVector<double>& values);
  3488. void removeDataBefore(double key);
  3489. void removeDataAfter(double key);
  3490. void removeData(double fromKey, double toKey);
  3491. void removeData(double key);
  3492. // reimplemented virtual methods:
  3493. virtual void clearData();
  3494. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  3495. protected:
  3496. // property members:
  3497. QCPBarDataMap* mData;
  3498. double mWidth;
  3499. WidthType mWidthType;
  3500. QCPBarsGroup* mBarsGroup;
  3501. double mBaseValue;
  3502. QPointer<QCPBars> mBarBelow, mBarAbove;
  3503. // reimplemented virtual methods:
  3504. virtual void draw(QCPPainter* painter);
  3505. virtual void drawLegendIcon(QCPPainter* painter, const QRectF& rect) const;
  3506. virtual QCPRange getKeyRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3507. virtual QCPRange getValueRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3508. // non-virtual methods:
  3509. void getVisibleDataBounds(QCPBarDataMap::const_iterator& lower,
  3510. QCPBarDataMap::const_iterator& upperEnd) const;
  3511. QPolygonF getBarPolygon(double key, double value) const;
  3512. void getPixelWidth(double key, double& lower, double& upper) const;
  3513. double getStackedBaseValue(double key, bool positive) const;
  3514. static void connectBars(QCPBars* lower, QCPBars* upper);
  3515. friend class QCustomPlot;
  3516. friend class QCPLegend;
  3517. friend class QCPBarsGroup;
  3518. };
  3519. /*! \file */
  3520. class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable
  3521. {
  3522. Q_OBJECT
  3523. /// \cond INCLUDE_QPROPERTIES
  3524. Q_PROPERTY(double key READ key WRITE setKey)
  3525. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  3526. Q_PROPERTY(double lowerQuartile READ lowerQuartile WRITE setLowerQuartile)
  3527. Q_PROPERTY(double median READ median WRITE setMedian)
  3528. Q_PROPERTY(double upperQuartile READ upperQuartile WRITE setUpperQuartile)
  3529. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  3530. Q_PROPERTY(QVector<double> outliers READ outliers WRITE setOutliers)
  3531. Q_PROPERTY(double width READ width WRITE setWidth)
  3532. Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth)
  3533. Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen)
  3534. Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen)
  3535. Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen)
  3536. Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle)
  3537. /// \endcond
  3538. public:
  3539. explicit QCPStatisticalBox(QCPAxis* keyAxis, QCPAxis* valueAxis);
  3540. // getters:
  3541. double key() const
  3542. {
  3543. return mKey;
  3544. }
  3545. double minimum() const
  3546. {
  3547. return mMinimum;
  3548. }
  3549. double lowerQuartile() const
  3550. {
  3551. return mLowerQuartile;
  3552. }
  3553. double median() const
  3554. {
  3555. return mMedian;
  3556. }
  3557. double upperQuartile() const
  3558. {
  3559. return mUpperQuartile;
  3560. }
  3561. double maximum() const
  3562. {
  3563. return mMaximum;
  3564. }
  3565. QVector<double> outliers() const
  3566. {
  3567. return mOutliers;
  3568. }
  3569. double width() const
  3570. {
  3571. return mWidth;
  3572. }
  3573. double whiskerWidth() const
  3574. {
  3575. return mWhiskerWidth;
  3576. }
  3577. QPen whiskerPen() const
  3578. {
  3579. return mWhiskerPen;
  3580. }
  3581. QPen whiskerBarPen() const
  3582. {
  3583. return mWhiskerBarPen;
  3584. }
  3585. QPen medianPen() const
  3586. {
  3587. return mMedianPen;
  3588. }
  3589. QCPScatterStyle outlierStyle() const
  3590. {
  3591. return mOutlierStyle;
  3592. }
  3593. // setters:
  3594. void setKey(double key);
  3595. void setMinimum(double value);
  3596. void setLowerQuartile(double value);
  3597. void setMedian(double value);
  3598. void setUpperQuartile(double value);
  3599. void setMaximum(double value);
  3600. void setOutliers(const QVector<double>& values);
  3601. void setData(double key, double minimum, double lowerQuartile, double median,
  3602. double upperQuartile, double maximum);
  3603. void setWidth(double width);
  3604. void setWhiskerWidth(double width);
  3605. void setWhiskerPen(const QPen& pen);
  3606. void setWhiskerBarPen(const QPen& pen);
  3607. void setMedianPen(const QPen& pen);
  3608. void setOutlierStyle(const QCPScatterStyle& style);
  3609. // non-property methods:
  3610. virtual void clearData();
  3611. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  3612. protected:
  3613. // property members:
  3614. QVector<double> mOutliers;
  3615. double mKey, mMinimum, mLowerQuartile, mMedian, mUpperQuartile, mMaximum;
  3616. double mWidth;
  3617. double mWhiskerWidth;
  3618. QPen mWhiskerPen, mWhiskerBarPen, mMedianPen;
  3619. QCPScatterStyle mOutlierStyle;
  3620. // reimplemented virtual methods:
  3621. virtual void draw(QCPPainter* painter);
  3622. virtual void drawLegendIcon(QCPPainter* painter, const QRectF& rect) const;
  3623. virtual QCPRange getKeyRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3624. virtual QCPRange getValueRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3625. // introduced virtual methods:
  3626. virtual void drawQuartileBox(QCPPainter* painter, QRectF* quartileBox = 0) const;
  3627. virtual void drawMedian(QCPPainter* painter) const;
  3628. virtual void drawWhiskers(QCPPainter* painter) const;
  3629. virtual void drawOutliers(QCPPainter* painter) const;
  3630. friend class QCustomPlot;
  3631. friend class QCPLegend;
  3632. };
  3633. class QCP_LIB_DECL QCPColorMapData
  3634. {
  3635. public:
  3636. QCPColorMapData(int keySize, int valueSize, const QCPRange& keyRange,
  3637. const QCPRange& valueRange);
  3638. ~QCPColorMapData();
  3639. QCPColorMapData(const QCPColorMapData& other);
  3640. QCPColorMapData& operator=(const QCPColorMapData& other);
  3641. // getters:
  3642. int keySize() const
  3643. {
  3644. return mKeySize;
  3645. }
  3646. int valueSize() const
  3647. {
  3648. return mValueSize;
  3649. }
  3650. QCPRange keyRange() const
  3651. {
  3652. return mKeyRange;
  3653. }
  3654. QCPRange valueRange() const
  3655. {
  3656. return mValueRange;
  3657. }
  3658. QCPRange dataBounds() const
  3659. {
  3660. return mDataBounds;
  3661. }
  3662. double data(double key, double value);
  3663. double cell(int keyIndex, int valueIndex);
  3664. // setters:
  3665. void setSize(int keySize, int valueSize);
  3666. void setKeySize(int keySize);
  3667. void setValueSize(int valueSize);
  3668. void setRange(const QCPRange& keyRange, const QCPRange& valueRange);
  3669. void setKeyRange(const QCPRange& keyRange);
  3670. void setValueRange(const QCPRange& valueRange);
  3671. void setData(double key, double value, double z);
  3672. void setCell(int keyIndex, int valueIndex, double z);
  3673. // non-property methods:
  3674. void recalculateDataBounds();
  3675. void clear();
  3676. void fill(double z);
  3677. bool isEmpty() const
  3678. {
  3679. return mIsEmpty;
  3680. }
  3681. void coordToCell(double key, double value, int* keyIndex, int* valueIndex) const;
  3682. void cellToCoord(int keyIndex, int valueIndex, double* key, double* value) const;
  3683. protected:
  3684. // property members:
  3685. int mKeySize, mValueSize;
  3686. QCPRange mKeyRange, mValueRange;
  3687. bool mIsEmpty;
  3688. // non-property members:
  3689. double* mData;
  3690. QCPRange mDataBounds;
  3691. bool mDataModified;
  3692. friend class QCPColorMap;
  3693. };
  3694. class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable
  3695. {
  3696. Q_OBJECT
  3697. /// \cond INCLUDE_QPROPERTIES
  3698. Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
  3699. Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY
  3700. dataScaleTypeChanged)
  3701. Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
  3702. Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate)
  3703. Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary)
  3704. Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale)
  3705. /// \endcond
  3706. public:
  3707. explicit QCPColorMap(QCPAxis* keyAxis, QCPAxis* valueAxis);
  3708. virtual ~QCPColorMap();
  3709. // getters:
  3710. QCPColorMapData* data() const
  3711. {
  3712. return mMapData;
  3713. }
  3714. QCPRange dataRange() const
  3715. {
  3716. return mDataRange;
  3717. }
  3718. QCPAxis::ScaleType dataScaleType() const
  3719. {
  3720. return mDataScaleType;
  3721. }
  3722. bool interpolate() const
  3723. {
  3724. return mInterpolate;
  3725. }
  3726. bool tightBoundary() const
  3727. {
  3728. return mTightBoundary;
  3729. }
  3730. QCPColorGradient gradient() const
  3731. {
  3732. return mGradient;
  3733. }
  3734. QCPColorScale* colorScale() const
  3735. {
  3736. return mColorScale.data();
  3737. }
  3738. // setters:
  3739. void setData(QCPColorMapData* data, bool copy = false);
  3740. Q_SLOT void setDataRange(const QCPRange& dataRange);
  3741. Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
  3742. Q_SLOT void setGradient(const QCPColorGradient& gradient);
  3743. void setInterpolate(bool enabled);
  3744. void setTightBoundary(bool enabled);
  3745. void setColorScale(QCPColorScale* colorScale);
  3746. // non-property methods:
  3747. void rescaleDataRange(bool recalculateDataBounds = false);
  3748. Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode = Qt::SmoothTransformation,
  3749. const QSize& thumbSize = QSize(32, 18));
  3750. // reimplemented virtual methods:
  3751. virtual void clearData();
  3752. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  3753. signals:
  3754. void dataRangeChanged(QCPRange newRange);
  3755. void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
  3756. void gradientChanged(QCPColorGradient newGradient);
  3757. protected:
  3758. // property members:
  3759. QCPRange mDataRange;
  3760. QCPAxis::ScaleType mDataScaleType;
  3761. QCPColorMapData* mMapData;
  3762. QCPColorGradient mGradient;
  3763. bool mInterpolate;
  3764. bool mTightBoundary;
  3765. QPointer<QCPColorScale> mColorScale;
  3766. // non-property members:
  3767. QImage mMapImage, mUndersampledMapImage;
  3768. QPixmap mLegendIcon;
  3769. bool mMapImageInvalidated;
  3770. // introduced virtual methods:
  3771. virtual void updateMapImage();
  3772. // reimplemented virtual methods:
  3773. virtual void draw(QCPPainter* painter);
  3774. virtual void drawLegendIcon(QCPPainter* painter, const QRectF& rect) const;
  3775. virtual QCPRange getKeyRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3776. virtual QCPRange getValueRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3777. friend class QCustomPlot;
  3778. friend class QCPLegend;
  3779. };
  3780. /*! \file */
  3781. class QCP_LIB_DECL QCPFinancialData
  3782. {
  3783. public:
  3784. QCPFinancialData();
  3785. QCPFinancialData(double key, double open, double high, double low, double close);
  3786. double key, open, high, low, close;
  3787. };
  3788. Q_DECLARE_TYPEINFO(QCPFinancialData, Q_MOVABLE_TYPE);
  3789. /*! \typedef QCPFinancialDataMap
  3790. Container for storing \ref QCPFinancialData items in a sorted fashion. The key of the map
  3791. is the key member of the QCPFinancialData instance.
  3792. This is the container in which QCPFinancial holds its data.
  3793. \see QCPFinancial, QCPFinancial::setData
  3794. */
  3795. typedef QMap<double, QCPFinancialData> QCPFinancialDataMap;
  3796. typedef QMapIterator<double, QCPFinancialData> QCPFinancialDataMapIterator;
  3797. typedef QMutableMapIterator<double, QCPFinancialData> QCPFinancialDataMutableMapIterator;
  3798. class QCP_LIB_DECL QCPFinancial : public QCPAbstractPlottable
  3799. {
  3800. Q_OBJECT
  3801. /// \cond INCLUDE_QPROPERTIES
  3802. Q_PROPERTY(ChartStyle chartStyle READ chartStyle WRITE setChartStyle)
  3803. Q_PROPERTY(double width READ width WRITE setWidth)
  3804. Q_PROPERTY(bool twoColored READ twoColored WRITE setTwoColored)
  3805. Q_PROPERTY(QBrush brushPositive READ brushPositive WRITE setBrushPositive)
  3806. Q_PROPERTY(QBrush brushNegative READ brushNegative WRITE setBrushNegative)
  3807. Q_PROPERTY(QPen penPositive READ penPositive WRITE setPenPositive)
  3808. Q_PROPERTY(QPen penNegative READ penNegative WRITE setPenNegative)
  3809. /// \endcond
  3810. public:
  3811. /*!
  3812. Defines the possible representations of OHLC data in the plot.
  3813. \see setChartStyle
  3814. */
  3815. enum ChartStyle {
  3816. csOhlc ///< Open-High-Low-Close bar representation
  3817. ,
  3818. csCandlestick ///< Candlestick representation
  3819. };
  3820. Q_ENUMS(ChartStyle)
  3821. explicit QCPFinancial(QCPAxis* keyAxis, QCPAxis* valueAxis);
  3822. virtual ~QCPFinancial();
  3823. // getters:
  3824. QCPFinancialDataMap* data() const
  3825. {
  3826. return mData;
  3827. }
  3828. ChartStyle chartStyle() const
  3829. {
  3830. return mChartStyle;
  3831. }
  3832. double width() const
  3833. {
  3834. return mWidth;
  3835. }
  3836. bool twoColored() const
  3837. {
  3838. return mTwoColored;
  3839. }
  3840. QBrush brushPositive() const
  3841. {
  3842. return mBrushPositive;
  3843. }
  3844. QBrush brushNegative() const
  3845. {
  3846. return mBrushNegative;
  3847. }
  3848. QPen penPositive() const
  3849. {
  3850. return mPenPositive;
  3851. }
  3852. QPen penNegative() const
  3853. {
  3854. return mPenNegative;
  3855. }
  3856. // setters:
  3857. void setData(QCPFinancialDataMap* data, bool copy = false);
  3858. void setData(const QVector<double>& key, const QVector<double>& open,
  3859. const QVector<double>& high, const QVector<double>& low,
  3860. const QVector<double>& close);
  3861. void setChartStyle(ChartStyle style);
  3862. void setWidth(double width);
  3863. void setTwoColored(bool twoColored);
  3864. void setBrushPositive(const QBrush& brush);
  3865. void setBrushNegative(const QBrush& brush);
  3866. void setPenPositive(const QPen& pen);
  3867. void setPenNegative(const QPen& pen);
  3868. // non-property methods:
  3869. void addData(const QCPFinancialDataMap& dataMap);
  3870. void addData(const QCPFinancialData& data);
  3871. void addData(double key, double open, double high, double low, double close);
  3872. void addData(const QVector<double>& key, const QVector<double>& open,
  3873. const QVector<double>& high, const QVector<double>& low,
  3874. const QVector<double>& close);
  3875. void removeDataBefore(double key);
  3876. void removeDataAfter(double key);
  3877. void removeData(double fromKey, double toKey);
  3878. void removeData(double key);
  3879. // reimplemented virtual methods:
  3880. virtual void clearData();
  3881. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  3882. // static methods:
  3883. static QCPFinancialDataMap timeSeriesToOhlc(const QVector<double>& time,
  3884. const QVector<double>& value, double timeBinSize,
  3885. double timeBinOffset = 0);
  3886. protected:
  3887. // property members:
  3888. QCPFinancialDataMap* mData;
  3889. ChartStyle mChartStyle;
  3890. double mWidth;
  3891. bool mTwoColored;
  3892. QBrush mBrushPositive, mBrushNegative;
  3893. QPen mPenPositive, mPenNegative;
  3894. // reimplemented virtual methods:
  3895. virtual void draw(QCPPainter* painter);
  3896. virtual void drawLegendIcon(QCPPainter* painter, const QRectF& rect) const;
  3897. virtual QCPRange getKeyRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3898. virtual QCPRange getValueRange(bool& foundRange, SignDomain inSignDomain = sdBoth) const;
  3899. // non-virtual methods:
  3900. void drawOhlcPlot(QCPPainter* painter, const QCPFinancialDataMap::const_iterator& begin,
  3901. const QCPFinancialDataMap::const_iterator& end);
  3902. void drawCandlestickPlot(QCPPainter* painter, const QCPFinancialDataMap::const_iterator& begin,
  3903. const QCPFinancialDataMap::const_iterator& end);
  3904. double ohlcSelectTest(const QPointF& pos, const QCPFinancialDataMap::const_iterator& begin,
  3905. const QCPFinancialDataMap::const_iterator& end) const;
  3906. double candlestickSelectTest(const QPointF& pos,
  3907. const QCPFinancialDataMap::const_iterator& begin,
  3908. const QCPFinancialDataMap::const_iterator& end) const;
  3909. void getVisibleDataBounds(QCPFinancialDataMap::const_iterator& lower,
  3910. QCPFinancialDataMap::const_iterator& upper) const;
  3911. friend class QCustomPlot;
  3912. friend class QCPLegend;
  3913. };
  3914. class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem
  3915. {
  3916. Q_OBJECT
  3917. /// \cond INCLUDE_QPROPERTIES
  3918. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  3919. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  3920. /// \endcond
  3921. public:
  3922. QCPItemStraightLine(QCustomPlot* parentPlot);
  3923. virtual ~QCPItemStraightLine();
  3924. // getters:
  3925. QPen pen() const
  3926. {
  3927. return mPen;
  3928. }
  3929. QPen selectedPen() const
  3930. {
  3931. return mSelectedPen;
  3932. }
  3933. // setters;
  3934. void setPen(const QPen& pen);
  3935. void setSelectedPen(const QPen& pen);
  3936. // reimplemented virtual methods:
  3937. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  3938. QCPItemPosition* const point1;
  3939. QCPItemPosition* const point2;
  3940. protected:
  3941. // property members:
  3942. QPen mPen, mSelectedPen;
  3943. // reimplemented virtual methods:
  3944. virtual void draw(QCPPainter* painter);
  3945. // non-virtual methods:
  3946. double distToStraightLine(const QVector2D& point1, const QVector2D& vec,
  3947. const QVector2D& point) const;
  3948. QLineF getRectClippedStraightLine(const QVector2D& point1, const QVector2D& vec,
  3949. const QRect& rect) const;
  3950. QPen mainPen() const;
  3951. };
  3952. class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem
  3953. {
  3954. Q_OBJECT
  3955. /// \cond INCLUDE_QPROPERTIES
  3956. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  3957. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  3958. Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
  3959. Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
  3960. /// \endcond
  3961. public:
  3962. QCPItemLine(QCustomPlot* parentPlot);
  3963. virtual ~QCPItemLine();
  3964. // getters:
  3965. QPen pen() const
  3966. {
  3967. return mPen;
  3968. }
  3969. QPen selectedPen() const
  3970. {
  3971. return mSelectedPen;
  3972. }
  3973. QCPLineEnding head() const
  3974. {
  3975. return mHead;
  3976. }
  3977. QCPLineEnding tail() const
  3978. {
  3979. return mTail;
  3980. }
  3981. // setters;
  3982. void setPen(const QPen& pen);
  3983. void setSelectedPen(const QPen& pen);
  3984. void setHead(const QCPLineEnding& head);
  3985. void setTail(const QCPLineEnding& tail);
  3986. // reimplemented virtual methods:
  3987. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  3988. QCPItemPosition* const start;
  3989. QCPItemPosition* const end;
  3990. protected:
  3991. // property members:
  3992. QPen mPen, mSelectedPen;
  3993. QCPLineEnding mHead, mTail;
  3994. // reimplemented virtual methods:
  3995. virtual void draw(QCPPainter* painter);
  3996. // non-virtual methods:
  3997. QLineF getRectClippedLine(const QVector2D& start, const QVector2D& end,
  3998. const QRect& rect) const;
  3999. QPen mainPen() const;
  4000. };
  4001. class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem
  4002. {
  4003. Q_OBJECT
  4004. /// \cond INCLUDE_QPROPERTIES
  4005. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  4006. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  4007. Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
  4008. Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
  4009. /// \endcond
  4010. public:
  4011. QCPItemCurve(QCustomPlot* parentPlot);
  4012. virtual ~QCPItemCurve();
  4013. // getters:
  4014. QPen pen() const
  4015. {
  4016. return mPen;
  4017. }
  4018. QPen selectedPen() const
  4019. {
  4020. return mSelectedPen;
  4021. }
  4022. QCPLineEnding head() const
  4023. {
  4024. return mHead;
  4025. }
  4026. QCPLineEnding tail() const
  4027. {
  4028. return mTail;
  4029. }
  4030. // setters;
  4031. void setPen(const QPen& pen);
  4032. void setSelectedPen(const QPen& pen);
  4033. void setHead(const QCPLineEnding& head);
  4034. void setTail(const QCPLineEnding& tail);
  4035. // reimplemented virtual methods:
  4036. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  4037. QCPItemPosition* const start;
  4038. QCPItemPosition* const startDir;
  4039. QCPItemPosition* const endDir;
  4040. QCPItemPosition* const end;
  4041. protected:
  4042. // property members:
  4043. QPen mPen, mSelectedPen;
  4044. QCPLineEnding mHead, mTail;
  4045. // reimplemented virtual methods:
  4046. virtual void draw(QCPPainter* painter);
  4047. // non-virtual methods:
  4048. QPen mainPen() const;
  4049. };
  4050. class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem
  4051. {
  4052. Q_OBJECT
  4053. /// \cond INCLUDE_QPROPERTIES
  4054. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  4055. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  4056. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  4057. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  4058. /// \endcond
  4059. public:
  4060. QCPItemRect(QCustomPlot* parentPlot);
  4061. virtual ~QCPItemRect();
  4062. // getters:
  4063. QPen pen() const
  4064. {
  4065. return mPen;
  4066. }
  4067. QPen selectedPen() const
  4068. {
  4069. return mSelectedPen;
  4070. }
  4071. QBrush brush() const
  4072. {
  4073. return mBrush;
  4074. }
  4075. QBrush selectedBrush() const
  4076. {
  4077. return mSelectedBrush;
  4078. }
  4079. // setters;
  4080. void setPen(const QPen& pen);
  4081. void setSelectedPen(const QPen& pen);
  4082. void setBrush(const QBrush& brush);
  4083. void setSelectedBrush(const QBrush& brush);
  4084. // reimplemented virtual methods:
  4085. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  4086. QCPItemPosition* const topLeft;
  4087. QCPItemPosition* const bottomRight;
  4088. QCPItemAnchor* const top;
  4089. QCPItemAnchor* const topRight;
  4090. QCPItemAnchor* const right;
  4091. QCPItemAnchor* const bottom;
  4092. QCPItemAnchor* const bottomLeft;
  4093. QCPItemAnchor* const left;
  4094. protected:
  4095. enum AnchorIndex { aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft };
  4096. // property members:
  4097. QPen mPen, mSelectedPen;
  4098. QBrush mBrush, mSelectedBrush;
  4099. // reimplemented virtual methods:
  4100. virtual void draw(QCPPainter* painter);
  4101. virtual QPointF anchorPixelPoint(int anchorId) const;
  4102. // non-virtual methods:
  4103. QPen mainPen() const;
  4104. QBrush mainBrush() const;
  4105. };
  4106. class QCP_LIB_DECL QCPItemText : public QCPAbstractItem
  4107. {
  4108. Q_OBJECT
  4109. /// \cond INCLUDE_QPROPERTIES
  4110. Q_PROPERTY(QColor color READ color WRITE setColor)
  4111. Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
  4112. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  4113. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  4114. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  4115. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  4116. Q_PROPERTY(QFont font READ font WRITE setFont)
  4117. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  4118. Q_PROPERTY(QString text READ text WRITE setText)
  4119. Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment)
  4120. Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment)
  4121. Q_PROPERTY(double rotation READ rotation WRITE setRotation)
  4122. Q_PROPERTY(QMargins padding READ padding WRITE setPadding)
  4123. /// \endcond
  4124. public:
  4125. QCPItemText(QCustomPlot* parentPlot);
  4126. virtual ~QCPItemText();
  4127. // getters:
  4128. QColor color() const
  4129. {
  4130. return mColor;
  4131. }
  4132. QColor selectedColor() const
  4133. {
  4134. return mSelectedColor;
  4135. }
  4136. QPen pen() const
  4137. {
  4138. return mPen;
  4139. }
  4140. QPen selectedPen() const
  4141. {
  4142. return mSelectedPen;
  4143. }
  4144. QBrush brush() const
  4145. {
  4146. return mBrush;
  4147. }
  4148. QBrush selectedBrush() const
  4149. {
  4150. return mSelectedBrush;
  4151. }
  4152. QFont font() const
  4153. {
  4154. return mFont;
  4155. }
  4156. QFont selectedFont() const
  4157. {
  4158. return mSelectedFont;
  4159. }
  4160. QString text() const
  4161. {
  4162. return mText;
  4163. }
  4164. Qt::Alignment positionAlignment() const
  4165. {
  4166. return mPositionAlignment;
  4167. }
  4168. Qt::Alignment textAlignment() const
  4169. {
  4170. return mTextAlignment;
  4171. }
  4172. double rotation() const
  4173. {
  4174. return mRotation;
  4175. }
  4176. QMargins padding() const
  4177. {
  4178. return mPadding;
  4179. }
  4180. // setters;
  4181. void setColor(const QColor& color);
  4182. void setSelectedColor(const QColor& color);
  4183. void setPen(const QPen& pen);
  4184. void setSelectedPen(const QPen& pen);
  4185. void setBrush(const QBrush& brush);
  4186. void setSelectedBrush(const QBrush& brush);
  4187. void setFont(const QFont& font);
  4188. void setSelectedFont(const QFont& font);
  4189. void setText(const QString& text);
  4190. void setPositionAlignment(Qt::Alignment alignment);
  4191. void setTextAlignment(Qt::Alignment alignment);
  4192. void setRotation(double degrees);
  4193. void setPadding(const QMargins& padding);
  4194. // reimplemented virtual methods:
  4195. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  4196. QCPItemPosition* const position;
  4197. QCPItemAnchor* const topLeft;
  4198. QCPItemAnchor* const top;
  4199. QCPItemAnchor* const topRight;
  4200. QCPItemAnchor* const right;
  4201. QCPItemAnchor* const bottomRight;
  4202. QCPItemAnchor* const bottom;
  4203. QCPItemAnchor* const bottomLeft;
  4204. QCPItemAnchor* const left;
  4205. protected:
  4206. enum AnchorIndex {
  4207. aiTopLeft,
  4208. aiTop,
  4209. aiTopRight,
  4210. aiRight,
  4211. aiBottomRight,
  4212. aiBottom,
  4213. aiBottomLeft,
  4214. aiLeft
  4215. };
  4216. // property members:
  4217. QColor mColor, mSelectedColor;
  4218. QPen mPen, mSelectedPen;
  4219. QBrush mBrush, mSelectedBrush;
  4220. QFont mFont, mSelectedFont;
  4221. QString mText;
  4222. Qt::Alignment mPositionAlignment;
  4223. Qt::Alignment mTextAlignment;
  4224. double mRotation;
  4225. QMargins mPadding;
  4226. // reimplemented virtual methods:
  4227. virtual void draw(QCPPainter* painter);
  4228. virtual QPointF anchorPixelPoint(int anchorId) const;
  4229. // non-virtual methods:
  4230. QPointF getTextDrawPoint(const QPointF& pos, const QRectF& rect,
  4231. Qt::Alignment positionAlignment) const;
  4232. QFont mainFont() const;
  4233. QColor mainColor() const;
  4234. QPen mainPen() const;
  4235. QBrush mainBrush() const;
  4236. };
  4237. class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem
  4238. {
  4239. Q_OBJECT
  4240. /// \cond INCLUDE_QPROPERTIES
  4241. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  4242. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  4243. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  4244. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  4245. /// \endcond
  4246. public:
  4247. QCPItemEllipse(QCustomPlot* parentPlot);
  4248. virtual ~QCPItemEllipse();
  4249. // getters:
  4250. QPen pen() const
  4251. {
  4252. return mPen;
  4253. }
  4254. QPen selectedPen() const
  4255. {
  4256. return mSelectedPen;
  4257. }
  4258. QBrush brush() const
  4259. {
  4260. return mBrush;
  4261. }
  4262. QBrush selectedBrush() const
  4263. {
  4264. return mSelectedBrush;
  4265. }
  4266. // setters;
  4267. void setPen(const QPen& pen);
  4268. void setSelectedPen(const QPen& pen);
  4269. void setBrush(const QBrush& brush);
  4270. void setSelectedBrush(const QBrush& brush);
  4271. // reimplemented virtual methods:
  4272. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  4273. QCPItemPosition* const topLeft;
  4274. QCPItemPosition* const bottomRight;
  4275. QCPItemAnchor* const topLeftRim;
  4276. QCPItemAnchor* const top;
  4277. QCPItemAnchor* const topRightRim;
  4278. QCPItemAnchor* const right;
  4279. QCPItemAnchor* const bottomRightRim;
  4280. QCPItemAnchor* const bottom;
  4281. QCPItemAnchor* const bottomLeftRim;
  4282. QCPItemAnchor* const left;
  4283. QCPItemAnchor* const center;
  4284. protected:
  4285. enum AnchorIndex {
  4286. aiTopLeftRim,
  4287. aiTop,
  4288. aiTopRightRim,
  4289. aiRight,
  4290. aiBottomRightRim,
  4291. aiBottom,
  4292. aiBottomLeftRim,
  4293. aiLeft,
  4294. aiCenter
  4295. };
  4296. // property members:
  4297. QPen mPen, mSelectedPen;
  4298. QBrush mBrush, mSelectedBrush;
  4299. // reimplemented virtual methods:
  4300. virtual void draw(QCPPainter* painter);
  4301. virtual QPointF anchorPixelPoint(int anchorId) const;
  4302. // non-virtual methods:
  4303. QPen mainPen() const;
  4304. QBrush mainBrush() const;
  4305. };
  4306. class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem
  4307. {
  4308. Q_OBJECT
  4309. /// \cond INCLUDE_QPROPERTIES
  4310. Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
  4311. Q_PROPERTY(bool scaled READ scaled WRITE setScaled)
  4312. Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode)
  4313. Q_PROPERTY(Qt::TransformationMode transformationMode READ transformationMode)
  4314. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  4315. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  4316. /// \endcond
  4317. public:
  4318. QCPItemPixmap(QCustomPlot* parentPlot);
  4319. virtual ~QCPItemPixmap();
  4320. // getters:
  4321. QPixmap pixmap() const
  4322. {
  4323. return mPixmap;
  4324. }
  4325. bool scaled() const
  4326. {
  4327. return mScaled;
  4328. }
  4329. Qt::AspectRatioMode aspectRatioMode() const
  4330. {
  4331. return mAspectRatioMode;
  4332. }
  4333. Qt::TransformationMode transformationMode() const
  4334. {
  4335. return mTransformationMode;
  4336. }
  4337. QPen pen() const
  4338. {
  4339. return mPen;
  4340. }
  4341. QPen selectedPen() const
  4342. {
  4343. return mSelectedPen;
  4344. }
  4345. // setters;
  4346. void setPixmap(const QPixmap& pixmap);
  4347. void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio,
  4348. Qt::TransformationMode transformationMode = Qt::SmoothTransformation);
  4349. void setPen(const QPen& pen);
  4350. void setSelectedPen(const QPen& pen);
  4351. // reimplemented virtual methods:
  4352. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  4353. QCPItemPosition* const topLeft;
  4354. QCPItemPosition* const bottomRight;
  4355. QCPItemAnchor* const top;
  4356. QCPItemAnchor* const topRight;
  4357. QCPItemAnchor* const right;
  4358. QCPItemAnchor* const bottom;
  4359. QCPItemAnchor* const bottomLeft;
  4360. QCPItemAnchor* const left;
  4361. protected:
  4362. enum AnchorIndex { aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft };
  4363. // property members:
  4364. QPixmap mPixmap;
  4365. QPixmap mScaledPixmap;
  4366. bool mScaled;
  4367. bool mScaledPixmapInvalidated;
  4368. Qt::AspectRatioMode mAspectRatioMode;
  4369. Qt::TransformationMode mTransformationMode;
  4370. QPen mPen, mSelectedPen;
  4371. // reimplemented virtual methods:
  4372. virtual void draw(QCPPainter* painter);
  4373. virtual QPointF anchorPixelPoint(int anchorId) const;
  4374. // non-virtual methods:
  4375. void updateScaledPixmap(QRect finalRect = QRect(), bool flipHorz = false,
  4376. bool flipVert = false);
  4377. QRect getFinalRect(bool* flippedHorz = 0, bool* flippedVert = 0) const;
  4378. QPen mainPen() const;
  4379. };
  4380. class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem
  4381. {
  4382. Q_OBJECT
  4383. /// \cond INCLUDE_QPROPERTIES
  4384. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  4385. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  4386. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  4387. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  4388. Q_PROPERTY(double size READ size WRITE setSize)
  4389. Q_PROPERTY(TracerStyle style READ style WRITE setStyle)
  4390. Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph)
  4391. Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey)
  4392. Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating)
  4393. /// \endcond
  4394. public:
  4395. /*!
  4396. The different visual appearances a tracer item can have. Some styles size may be controlled
  4397. with \ref setSize.
  4398. \see setStyle
  4399. */
  4400. enum TracerStyle {
  4401. tsNone ///< The tracer is not visible
  4402. ,
  4403. tsPlus ///< A plus shaped crosshair with limited size
  4404. ,
  4405. tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect
  4406. ,
  4407. tsCircle ///< A circle
  4408. ,
  4409. tsSquare ///< A square
  4410. };
  4411. Q_ENUMS(TracerStyle)
  4412. QCPItemTracer(QCustomPlot* parentPlot);
  4413. virtual ~QCPItemTracer();
  4414. // getters:
  4415. QPen pen() const
  4416. {
  4417. return mPen;
  4418. }
  4419. QPen selectedPen() const
  4420. {
  4421. return mSelectedPen;
  4422. }
  4423. QBrush brush() const
  4424. {
  4425. return mBrush;
  4426. }
  4427. QBrush selectedBrush() const
  4428. {
  4429. return mSelectedBrush;
  4430. }
  4431. double size() const
  4432. {
  4433. return mSize;
  4434. }
  4435. TracerStyle style() const
  4436. {
  4437. return mStyle;
  4438. }
  4439. QCPGraph* graph() const
  4440. {
  4441. return mGraph;
  4442. }
  4443. double graphKey() const
  4444. {
  4445. return mGraphKey;
  4446. }
  4447. bool interpolating() const
  4448. {
  4449. return mInterpolating;
  4450. }
  4451. // setters;
  4452. void setPen(const QPen& pen);
  4453. void setSelectedPen(const QPen& pen);
  4454. void setBrush(const QBrush& brush);
  4455. void setSelectedBrush(const QBrush& brush);
  4456. void setSize(double size);
  4457. void setStyle(TracerStyle style);
  4458. void setGraph(QCPGraph* graph);
  4459. void setGraphKey(double key);
  4460. void setInterpolating(bool enabled);
  4461. // reimplemented virtual methods:
  4462. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  4463. // non-virtual methods:
  4464. void updatePosition();
  4465. QCPItemPosition* const position;
  4466. protected:
  4467. // property members:
  4468. QPen mPen, mSelectedPen;
  4469. QBrush mBrush, mSelectedBrush;
  4470. double mSize;
  4471. TracerStyle mStyle;
  4472. QCPGraph* mGraph;
  4473. double mGraphKey;
  4474. bool mInterpolating;
  4475. // reimplemented virtual methods:
  4476. virtual void draw(QCPPainter* painter);
  4477. // non-virtual methods:
  4478. QPen mainPen() const;
  4479. QBrush mainBrush() const;
  4480. };
  4481. class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem
  4482. {
  4483. Q_OBJECT
  4484. /// \cond INCLUDE_QPROPERTIES
  4485. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  4486. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  4487. Q_PROPERTY(double length READ length WRITE setLength)
  4488. Q_PROPERTY(BracketStyle style READ style WRITE setStyle)
  4489. /// \endcond
  4490. public:
  4491. enum BracketStyle {
  4492. bsSquare ///< A brace with angled edges
  4493. ,
  4494. bsRound ///< A brace with round edges
  4495. ,
  4496. bsCurly ///< A curly brace
  4497. ,
  4498. bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression
  4499. };
  4500. QCPItemBracket(QCustomPlot* parentPlot);
  4501. virtual ~QCPItemBracket();
  4502. // getters:
  4503. QPen pen() const
  4504. {
  4505. return mPen;
  4506. }
  4507. QPen selectedPen() const
  4508. {
  4509. return mSelectedPen;
  4510. }
  4511. double length() const
  4512. {
  4513. return mLength;
  4514. }
  4515. BracketStyle style() const
  4516. {
  4517. return mStyle;
  4518. }
  4519. // setters;
  4520. void setPen(const QPen& pen);
  4521. void setSelectedPen(const QPen& pen);
  4522. void setLength(double length);
  4523. void setStyle(BracketStyle style);
  4524. // reimplemented virtual methods:
  4525. virtual double selectTest(const QPointF& pos, bool onlySelectable, QVariant* details = 0) const;
  4526. QCPItemPosition* const left;
  4527. QCPItemPosition* const right;
  4528. QCPItemAnchor* const center;
  4529. protected:
  4530. // property members:
  4531. enum AnchorIndex { aiCenter };
  4532. QPen mPen, mSelectedPen;
  4533. double mLength;
  4534. BracketStyle mStyle;
  4535. // reimplemented virtual methods:
  4536. virtual void draw(QCPPainter* painter);
  4537. virtual QPointF anchorPixelPoint(int anchorId) const;
  4538. // non-virtual methods:
  4539. QPen mainPen() const;
  4540. };
  4541. #endif // QCUSTOMPLOT_H