qcustomplot.h 303 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774
  1. /***************************************************************************
  2. ** **
  3. ** QCustomPlot, an easy to use, modern plotting widget for Qt **
  4. ** Copyright (C) 2011-2022 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: https://www.qcustomplot.com/ **
  22. ** Date: 06.11.22 **
  23. ** Version: 2.1.1 **
  24. ****************************************************************************/
  25. #ifndef QCUSTOMPLOT_H
  26. #define QCUSTOMPLOT_H
  27. #include <QtCore/qglobal.h>
  28. // some Qt version/configuration dependent macros to include or exclude certain code paths:
  29. #ifdef QCUSTOMPLOT_USE_OPENGL
  30. # if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
  31. # define QCP_OPENGL_PBUFFER
  32. # else
  33. # define QCP_OPENGL_FBO
  34. # endif
  35. # if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
  36. # define QCP_OPENGL_OFFSCREENSURFACE
  37. # endif
  38. #endif
  39. #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
  40. # define QCP_DEVICEPIXELRATIO_SUPPORTED
  41. # if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
  42. # define QCP_DEVICEPIXELRATIO_FLOAT
  43. # endif
  44. #endif
  45. #include <QtCore/QObject>
  46. #include <QtCore/QPointer>
  47. #include <QtCore/QSharedPointer>
  48. #include <QtCore/QTimer>
  49. #include <QtGui/QPainter>
  50. #include <QtGui/QPainterPath>
  51. #include <QtGui/QPaintEvent>
  52. #include <QtGui/QMouseEvent>
  53. #include <QtGui/QWheelEvent>
  54. #include <QtGui/QPixmap>
  55. #include <QtCore/QVector>
  56. #include <QtCore/QString>
  57. #include <QtCore/QDateTime>
  58. #include <QtCore/QMultiMap>
  59. #include <QtCore/QFlags>
  60. #include <QtCore/QDebug>
  61. #include <QtCore/QStack>
  62. #include <QtCore/QCache>
  63. #include <QtCore/QMargins>
  64. #include <qmath.h>
  65. #include <limits>
  66. #include <algorithm>
  67. #ifdef QCP_OPENGL_FBO
  68. # include <QtGui/QOpenGLContext>
  69. # if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
  70. # include <QtGui/QOpenGLFramebufferObject>
  71. # else
  72. # include <QOpenGLFramebufferObject>
  73. # include <QOpenGLPaintDevice>
  74. # endif
  75. # ifdef QCP_OPENGL_OFFSCREENSURFACE
  76. # include <QtGui/QOffscreenSurface>
  77. # else
  78. # include <QtGui/QWindow>
  79. # endif
  80. #endif
  81. #ifdef QCP_OPENGL_PBUFFER
  82. # include <QtOpenGL/QGLPixelBuffer>
  83. #endif
  84. #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
  85. # include <qnumeric.h>
  86. # include <QtGui/QWidget>
  87. # include <QtGui/QPrinter>
  88. # include <QtGui/QPrintEngine>
  89. #else
  90. # include <QtNumeric>
  91. # include <QtWidgets/QWidget>
  92. # include <QtPrintSupport/QtPrintSupport>
  93. #endif
  94. #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
  95. # include <QtCore/QElapsedTimer>
  96. #endif
  97. # if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
  98. # include <QtCore/QTimeZone>
  99. #endif
  100. class QCPPainter;
  101. class QCustomPlot;
  102. class QCPLayerable;
  103. class QCPLayoutElement;
  104. class QCPLayout;
  105. class QCPAxis;
  106. class QCPAxisRect;
  107. class QCPAxisPainterPrivate;
  108. class QCPAbstractPlottable;
  109. class QCPGraph;
  110. class QCPAbstractItem;
  111. class QCPPlottableInterface1D;
  112. class QCPLegend;
  113. class QCPItemPosition;
  114. class QCPLayer;
  115. class QCPAbstractLegendItem;
  116. class QCPSelectionRect;
  117. class QCPColorMap;
  118. class QCPColorScale;
  119. class QCPBars;
  120. class QCPPolarAxisRadial;
  121. class QCPPolarAxisAngular;
  122. class QCPPolarGrid;
  123. class QCPPolarGraph;
  124. /* including file 'src/global.h' */
  125. /* modified 2022-11-06T12:45:57, size 18102 */
  126. #define QCUSTOMPLOT_VERSION_STR "2.1.1"
  127. #define QCUSTOMPLOT_VERSION 0x020101
  128. // decl definitions for shared library compilation/usage:
  129. #if defined(QT_STATIC_BUILD)
  130. # define QCP_LIB_DECL
  131. #elif defined(QCUSTOMPLOT_COMPILE_LIBRARY)
  132. # define QCP_LIB_DECL Q_DECL_EXPORT
  133. #elif defined(QCUSTOMPLOT_USE_LIBRARY)
  134. # define QCP_LIB_DECL Q_DECL_IMPORT
  135. #else
  136. # define QCP_LIB_DECL
  137. #endif
  138. // define empty macro for Q_DECL_OVERRIDE if it doesn't exist (Qt < 5)
  139. #ifndef Q_DECL_OVERRIDE
  140. # define Q_DECL_OVERRIDE
  141. #endif
  142. /*!
  143. The QCP Namespace contains general enums, QFlags and functions used throughout the QCustomPlot
  144. library.
  145. It provides QMetaObject-based reflection of its enums and flags via \a QCP::staticMetaObject.
  146. */
  147. // Qt version < 6.2.0: to get metatypes Q_GADGET/Q_ENUMS/Q_FLAGS in namespace we have to make it look like a class during moc-run
  148. #if QT_VERSION >= 0x060200 // don't use QT_VERSION_CHECK here, some moc versions don't understand it
  149. namespace QCP {
  150. Q_NAMESPACE // this is how to add the staticMetaObject to namespaces in newer Qt versions
  151. #else // Qt version older than 6.2.0
  152. # ifndef Q_MOC_RUN
  153. namespace QCP {
  154. # else // not in moc run
  155. class QCP {
  156. Q_GADGET
  157. Q_ENUMS(ExportPen)
  158. Q_ENUMS(ResolutionUnit)
  159. Q_ENUMS(SignDomain)
  160. Q_ENUMS(MarginSide)
  161. Q_ENUMS(AntialiasedElement)
  162. Q_ENUMS(PlottingHint)
  163. Q_ENUMS(Interaction)
  164. Q_ENUMS(SelectionRectMode)
  165. Q_ENUMS(SelectionType)
  166. Q_FLAGS(AntialiasedElements)
  167. Q_FLAGS(PlottingHints)
  168. Q_FLAGS(MarginSides)
  169. Q_FLAGS(Interactions)
  170. public:
  171. # endif
  172. #endif
  173. /*!
  174. Defines the different units in which the image resolution can be specified in the export
  175. functions.
  176. \see QCustomPlot::savePng, QCustomPlot::saveJpg, QCustomPlot::saveBmp, QCustomPlot::saveRastered
  177. */
  178. enum ResolutionUnit { ruDotsPerMeter ///< Resolution is given in dots per meter (dpm)
  179. ,ruDotsPerCentimeter ///< Resolution is given in dots per centimeter (dpcm)
  180. ,ruDotsPerInch ///< Resolution is given in dots per inch (DPI/PPI)
  181. };
  182. /*!
  183. Defines how cosmetic pens (pens with numerical width 0) are handled during export.
  184. \see QCustomPlot::savePdf
  185. */
  186. enum ExportPen { epNoCosmetic ///< Cosmetic pens are converted to pens with pixel width 1 when exporting
  187. ,epAllowCosmetic ///< Cosmetic pens are exported normally (e.g. in PDF exports, cosmetic pens always appear as 1 pixel on screen, independent of viewer zoom level)
  188. };
  189. /*!
  190. Represents negative and positive sign domain, e.g. for passing to \ref
  191. QCPAbstractPlottable::getKeyRange and \ref QCPAbstractPlottable::getValueRange.
  192. This is primarily needed when working with logarithmic axis scales, since only one of the sign
  193. domains can be visible at a time.
  194. */
  195. enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero
  196. ,sdBoth ///< Both sign domains, including zero, i.e. all numbers
  197. ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero
  198. };
  199. /*!
  200. Defines the sides of a rectangular entity to which margins can be applied.
  201. \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins
  202. */
  203. enum MarginSide { msLeft = 0x01 ///< <tt>0x01</tt> left margin
  204. ,msRight = 0x02 ///< <tt>0x02</tt> right margin
  205. ,msTop = 0x04 ///< <tt>0x04</tt> top margin
  206. ,msBottom = 0x08 ///< <tt>0x08</tt> bottom margin
  207. ,msAll = 0xFF ///< <tt>0xFF</tt> all margins
  208. ,msNone = 0x00 ///< <tt>0x00</tt> no margin
  209. };
  210. Q_DECLARE_FLAGS(MarginSides, MarginSide)
  211. /*!
  212. Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is
  213. neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective
  214. element how it is drawn. Typically it provides a \a setAntialiased function for this.
  215. \c AntialiasedElements is a flag of or-combined elements of this enum type.
  216. \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements
  217. */
  218. enum AntialiasedElement { aeAxes = 0x0001 ///< <tt>0x0001</tt> Axis base line and tick marks
  219. ,aeGrid = 0x0002 ///< <tt>0x0002</tt> Grid lines
  220. ,aeSubGrid = 0x0004 ///< <tt>0x0004</tt> Sub grid lines
  221. ,aeLegend = 0x0008 ///< <tt>0x0008</tt> Legend box
  222. ,aeLegendItems = 0x0010 ///< <tt>0x0010</tt> Legend items
  223. ,aePlottables = 0x0020 ///< <tt>0x0020</tt> Main lines of plottables
  224. ,aeItems = 0x0040 ///< <tt>0x0040</tt> Main lines of items
  225. ,aeScatters = 0x0080 ///< <tt>0x0080</tt> Scatter symbols of plottables (excluding scatter symbols of type ssPixmap)
  226. ,aeFills = 0x0100 ///< <tt>0x0100</tt> Borders of fills (e.g. under or between graphs)
  227. ,aeZeroLine = 0x0200 ///< <tt>0x0200</tt> Zero-lines, see \ref QCPGrid::setZeroLinePen
  228. ,aeOther = 0x8000 ///< <tt>0x8000</tt> Other elements that don't fit into any of the existing categories
  229. ,aeAll = 0xFFFF ///< <tt>0xFFFF</tt> All elements
  230. ,aeNone = 0x0000 ///< <tt>0x0000</tt> No elements
  231. };
  232. Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement)
  233. /*!
  234. Defines plotting hints that control various aspects of the quality and speed of plotting.
  235. \see QCustomPlot::setPlottingHints
  236. */
  237. enum PlottingHint { phNone = 0x000 ///< <tt>0x000</tt> No hints are set
  238. ,phFastPolylines = 0x001 ///< <tt>0x001</tt> Graph/Curve lines are drawn with a faster method. This reduces the quality especially of the line segment
  239. ///< joins, thus is most effective for pen sizes larger than 1. It is only used for solid line pens.
  240. ,phImmediateRefresh = 0x002 ///< <tt>0x002</tt> causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpRefreshHint.
  241. ///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse).
  242. ,phCacheLabels = 0x004 ///< <tt>0x004</tt> axis (tick) labels will be cached as pixmaps, increasing replot performance.
  243. };
  244. Q_DECLARE_FLAGS(PlottingHints, PlottingHint)
  245. /*!
  246. Defines the mouse interactions possible with QCustomPlot.
  247. \c Interactions is a flag of or-combined elements of this enum type.
  248. \see QCustomPlot::setInteractions
  249. */
  250. enum Interaction { iNone = 0x000 ///< <tt>0x000</tt> None of the interactions are possible
  251. ,iRangeDrag = 0x001 ///< <tt>0x001</tt> Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes)
  252. ,iRangeZoom = 0x002 ///< <tt>0x002</tt> Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes)
  253. ,iMultiSelect = 0x004 ///< <tt>0x004</tt> The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking
  254. ,iSelectPlottables = 0x008 ///< <tt>0x008</tt> Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable)
  255. ,iSelectAxes = 0x010 ///< <tt>0x010</tt> Axes are selectable (or parts of them, see QCPAxis::setSelectableParts)
  256. ,iSelectLegend = 0x020 ///< <tt>0x020</tt> Legends are selectable (or their child items, see QCPLegend::setSelectableParts)
  257. ,iSelectItems = 0x040 ///< <tt>0x040</tt> Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem)
  258. ,iSelectOther = 0x080 ///< <tt>0x080</tt> All other objects are selectable (e.g. your own derived layerables, other layout elements,...)
  259. ,iSelectPlottablesBeyondAxisRect = 0x100 ///< <tt>0x100</tt> When performing plottable selection/hit tests, this flag extends the sensitive area beyond the axis rect
  260. };
  261. Q_DECLARE_FLAGS(Interactions, Interaction)
  262. /*!
  263. Defines the behaviour of the selection rect.
  264. \see QCustomPlot::setSelectionRectMode, QCustomPlot::selectionRect, QCPSelectionRect
  265. */
  266. enum SelectionRectMode { srmNone ///< The selection rect is disabled, and all mouse events are forwarded to the underlying objects, e.g. for axis range dragging
  267. ,srmZoom ///< When dragging the mouse, a selection rect becomes active. Upon releasing, the axes that are currently set as range zoom axes (\ref QCPAxisRect::setRangeZoomAxes) will have their ranges zoomed accordingly.
  268. ,srmSelect ///< When dragging the mouse, a selection rect becomes active. Upon releasing, plottable data points that were within the selection rect are selected, if the plottable's selectability setting permits. (See \ref dataselection "data selection mechanism" for details.)
  269. ,srmCustom ///< When dragging the mouse, a selection rect becomes active. It is the programmer's responsibility to connect according slots to the selection rect's signals (e.g. \ref QCPSelectionRect::accepted) in order to process the user interaction.
  270. };
  271. /*!
  272. Defines the different ways a plottable can be selected. These images show the effect of the
  273. different selection types, when the indicated selection rect was dragged:
  274. <center>
  275. <table>
  276. <tr>
  277. <td>\image html selectiontype-none.png stNone</td>
  278. <td>\image html selectiontype-whole.png stWhole</td>
  279. <td>\image html selectiontype-singledata.png stSingleData</td>
  280. <td>\image html selectiontype-datarange.png stDataRange</td>
  281. <td>\image html selectiontype-multipledataranges.png stMultipleDataRanges</td>
  282. </tr>
  283. </table>
  284. </center>
  285. \see QCPAbstractPlottable::setSelectable, QCPDataSelection::enforceType
  286. */
  287. enum SelectionType { stNone ///< The plottable is not selectable
  288. ,stWhole ///< Selection behaves like \ref stMultipleDataRanges, but if there are any data points selected, the entire plottable is drawn as selected.
  289. ,stSingleData ///< One individual data point can be selected at a time
  290. ,stDataRange ///< Multiple contiguous data points (a data range) can be selected
  291. ,stMultipleDataRanges ///< Any combination of data points/ranges can be selected
  292. };
  293. /*! \internal
  294. Returns whether the specified \a value is considered an invalid data value for plottables (i.e.
  295. is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the
  296. compiler flag \c QCUSTOMPLOT_CHECK_DATA is set.
  297. */
  298. inline bool isInvalidData(double value)
  299. {
  300. return qIsNaN(value) || qIsInf(value);
  301. }
  302. /*! \internal
  303. \overload
  304. Checks two arguments instead of one.
  305. */
  306. inline bool isInvalidData(double value1, double value2)
  307. {
  308. return isInvalidData(value1) || isInvalidData(value2);
  309. }
  310. /*! \internal
  311. Sets the specified \a side of \a margins to \a value
  312. \see getMarginValue
  313. */
  314. inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value)
  315. {
  316. switch (side)
  317. {
  318. case QCP::msLeft: margins.setLeft(value); break;
  319. case QCP::msRight: margins.setRight(value); break;
  320. case QCP::msTop: margins.setTop(value); break;
  321. case QCP::msBottom: margins.setBottom(value); break;
  322. case QCP::msAll: margins = QMargins(value, value, value, value); break;
  323. default: break;
  324. }
  325. }
  326. /*! \internal
  327. Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or
  328. \ref QCP::msAll, returns 0.
  329. \see setMarginValue
  330. */
  331. inline int getMarginValue(const QMargins &margins, QCP::MarginSide side)
  332. {
  333. switch (side)
  334. {
  335. case QCP::msLeft: return margins.left();
  336. case QCP::msRight: return margins.right();
  337. case QCP::msTop: return margins.top();
  338. case QCP::msBottom: return margins.bottom();
  339. default: break;
  340. }
  341. return 0;
  342. }
  343. // for newer Qt versions we have to declare the enums/flags as metatypes inside the namespace using Q_ENUM_NS/Q_FLAG_NS:
  344. // if you change anything here, don't forget to change it for older Qt versions below, too,
  345. // and at the start of the namespace in the fake moc-run class
  346. #if QT_VERSION >= 0x060200
  347. Q_ENUM_NS(ExportPen)
  348. Q_ENUM_NS(ResolutionUnit)
  349. Q_ENUM_NS(SignDomain)
  350. Q_ENUM_NS(MarginSide)
  351. Q_ENUM_NS(AntialiasedElement)
  352. Q_ENUM_NS(PlottingHint)
  353. Q_ENUM_NS(Interaction)
  354. Q_ENUM_NS(SelectionRectMode)
  355. Q_ENUM_NS(SelectionType)
  356. Q_FLAG_NS(AntialiasedElements)
  357. Q_FLAG_NS(PlottingHints)
  358. Q_FLAG_NS(MarginSides)
  359. Q_FLAG_NS(Interactions)
  360. #else
  361. extern const QMetaObject staticMetaObject;
  362. #endif
  363. } // end of namespace QCP
  364. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
  365. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
  366. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides)
  367. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions)
  368. // for older Qt versions we have to declare the enums/flags as metatypes outside the namespace using Q_DECLARE_METATYPE:
  369. // if you change anything here, don't forget to change it for newer Qt versions above, too,
  370. // and at the start of the namespace in the fake moc-run class
  371. #if QT_VERSION < QT_VERSION_CHECK(6, 2, 0)
  372. Q_DECLARE_METATYPE(QCP::ExportPen)
  373. Q_DECLARE_METATYPE(QCP::ResolutionUnit)
  374. Q_DECLARE_METATYPE(QCP::SignDomain)
  375. Q_DECLARE_METATYPE(QCP::MarginSide)
  376. Q_DECLARE_METATYPE(QCP::AntialiasedElement)
  377. Q_DECLARE_METATYPE(QCP::PlottingHint)
  378. Q_DECLARE_METATYPE(QCP::Interaction)
  379. Q_DECLARE_METATYPE(QCP::SelectionRectMode)
  380. Q_DECLARE_METATYPE(QCP::SelectionType)
  381. #endif
  382. /* end of 'src/global.h' */
  383. /* including file 'src/vector2d.h' */
  384. /* modified 2022-11-06T12:45:56, size 4988 */
  385. class QCP_LIB_DECL QCPVector2D
  386. {
  387. public:
  388. QCPVector2D();
  389. QCPVector2D(double x, double y);
  390. QCPVector2D(const QPoint &point);
  391. QCPVector2D(const QPointF &point);
  392. // getters:
  393. double x() const { return mX; }
  394. double y() const { return mY; }
  395. double &rx() { return mX; }
  396. double &ry() { return mY; }
  397. // setters:
  398. void setX(double x) { mX = x; }
  399. void setY(double y) { mY = y; }
  400. // non-virtual methods:
  401. double length() const { return qSqrt(mX*mX+mY*mY); }
  402. double lengthSquared() const { return mX*mX+mY*mY; }
  403. double angle() const { return qAtan2(mY, mX); }
  404. QPoint toPoint() const { return QPoint(int(mX), int(mY)); }
  405. QPointF toPointF() const { return QPointF(mX, mY); }
  406. bool isNull() const { return qIsNull(mX) && qIsNull(mY); }
  407. void normalize();
  408. QCPVector2D normalized() const;
  409. QCPVector2D perpendicular() const { return QCPVector2D(-mY, mX); }
  410. double dot(const QCPVector2D &vec) const { return mX*vec.mX+mY*vec.mY; }
  411. double distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const;
  412. double distanceSquaredToLine(const QLineF &line) const;
  413. double distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const;
  414. QCPVector2D &operator*=(double factor);
  415. QCPVector2D &operator/=(double divisor);
  416. QCPVector2D &operator+=(const QCPVector2D &vector);
  417. QCPVector2D &operator-=(const QCPVector2D &vector);
  418. private:
  419. // property members:
  420. double mX, mY;
  421. friend inline const QCPVector2D operator*(double factor, const QCPVector2D &vec);
  422. friend inline const QCPVector2D operator*(const QCPVector2D &vec, double factor);
  423. friend inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor);
  424. friend inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2);
  425. friend inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2);
  426. friend inline const QCPVector2D operator-(const QCPVector2D &vec);
  427. };
  428. Q_DECLARE_TYPEINFO(QCPVector2D, Q_MOVABLE_TYPE);
  429. inline const QCPVector2D operator*(double factor, const QCPVector2D &vec) { return QCPVector2D(vec.mX*factor, vec.mY*factor); }
  430. inline const QCPVector2D operator*(const QCPVector2D &vec, double factor) { return QCPVector2D(vec.mX*factor, vec.mY*factor); }
  431. inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor) { return QCPVector2D(vec.mX/divisor, vec.mY/divisor); }
  432. inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX+vec2.mX, vec1.mY+vec2.mY); }
  433. inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX-vec2.mX, vec1.mY-vec2.mY); }
  434. inline const QCPVector2D operator-(const QCPVector2D &vec) { return QCPVector2D(-vec.mX, -vec.mY); }
  435. /*! \relates QCPVector2D
  436. Prints \a vec in a human readable format to the qDebug output.
  437. */
  438. inline QDebug operator<< (QDebug d, const QCPVector2D &vec)
  439. {
  440. d.nospace() << "QCPVector2D(" << vec.x() << ", " << vec.y() << ")";
  441. return d.space();
  442. }
  443. /* end of 'src/vector2d.h' */
  444. /* including file 'src/painter.h' */
  445. /* modified 2022-11-06T12:45:56, size 4035 */
  446. class QCP_LIB_DECL QCPPainter : public QPainter
  447. {
  448. Q_GADGET
  449. public:
  450. /*!
  451. Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds,
  452. depending on whether they are wanted on the respective output device.
  453. */
  454. enum PainterMode { pmDefault = 0x00 ///< <tt>0x00</tt> Default mode for painting on screen devices
  455. ,pmVectorized = 0x01 ///< <tt>0x01</tt> Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes.
  456. ,pmNoCaching = 0x02 ///< <tt>0x02</tt> Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels
  457. ,pmNonCosmetic = 0x04 ///< <tt>0x04</tt> Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.)
  458. };
  459. Q_ENUMS(PainterMode)
  460. Q_FLAGS(PainterModes)
  461. Q_DECLARE_FLAGS(PainterModes, PainterMode)
  462. QCPPainter();
  463. explicit QCPPainter(QPaintDevice *device);
  464. // getters:
  465. bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); }
  466. PainterModes modes() const { return mModes; }
  467. // setters:
  468. void setAntialiasing(bool enabled);
  469. void setMode(PainterMode mode, bool enabled=true);
  470. void setModes(PainterModes modes);
  471. // methods hiding non-virtual base class functions (QPainter bug workarounds):
  472. bool begin(QPaintDevice *device);
  473. void setPen(const QPen &pen);
  474. void setPen(const QColor &color);
  475. void setPen(Qt::PenStyle penStyle);
  476. void drawLine(const QLineF &line);
  477. void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));}
  478. void save();
  479. void restore();
  480. // non-virtual methods:
  481. void makeNonCosmetic();
  482. protected:
  483. // property members:
  484. PainterModes mModes;
  485. bool mIsAntialiasing;
  486. // non-property members:
  487. QStack<bool> mAntialiasingStack;
  488. };
  489. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes)
  490. Q_DECLARE_METATYPE(QCPPainter::PainterMode)
  491. /* end of 'src/painter.h' */
  492. /* including file 'src/paintbuffer.h' */
  493. /* modified 2022-11-06T12:45:56, size 5006 */
  494. class QCP_LIB_DECL QCPAbstractPaintBuffer
  495. {
  496. public:
  497. explicit QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio);
  498. virtual ~QCPAbstractPaintBuffer();
  499. // getters:
  500. QSize size() const { return mSize; }
  501. bool invalidated() const { return mInvalidated; }
  502. double devicePixelRatio() const { return mDevicePixelRatio; }
  503. // setters:
  504. void setSize(const QSize &size);
  505. void setInvalidated(bool invalidated=true);
  506. void setDevicePixelRatio(double ratio);
  507. // introduced virtual methods:
  508. virtual QCPPainter *startPainting() = 0;
  509. virtual void donePainting() {}
  510. virtual void draw(QCPPainter *painter) const = 0;
  511. virtual void clear(const QColor &color) = 0;
  512. protected:
  513. // property members:
  514. QSize mSize;
  515. double mDevicePixelRatio;
  516. // non-property members:
  517. bool mInvalidated;
  518. // introduced virtual methods:
  519. virtual void reallocateBuffer() = 0;
  520. };
  521. class QCP_LIB_DECL QCPPaintBufferPixmap : public QCPAbstractPaintBuffer
  522. {
  523. public:
  524. explicit QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio);
  525. virtual ~QCPPaintBufferPixmap() Q_DECL_OVERRIDE;
  526. // reimplemented virtual methods:
  527. virtual QCPPainter *startPainting() Q_DECL_OVERRIDE;
  528. virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE;
  529. void clear(const QColor &color) Q_DECL_OVERRIDE;
  530. protected:
  531. // non-property members:
  532. QPixmap mBuffer;
  533. // reimplemented virtual methods:
  534. virtual void reallocateBuffer() Q_DECL_OVERRIDE;
  535. };
  536. #ifdef QCP_OPENGL_PBUFFER
  537. class QCP_LIB_DECL QCPPaintBufferGlPbuffer : public QCPAbstractPaintBuffer
  538. {
  539. public:
  540. explicit QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples);
  541. virtual ~QCPPaintBufferGlPbuffer() Q_DECL_OVERRIDE;
  542. // reimplemented virtual methods:
  543. virtual QCPPainter *startPainting() Q_DECL_OVERRIDE;
  544. virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE;
  545. void clear(const QColor &color) Q_DECL_OVERRIDE;
  546. protected:
  547. // non-property members:
  548. QGLPixelBuffer *mGlPBuffer;
  549. int mMultisamples;
  550. // reimplemented virtual methods:
  551. virtual void reallocateBuffer() Q_DECL_OVERRIDE;
  552. };
  553. #endif // QCP_OPENGL_PBUFFER
  554. #ifdef QCP_OPENGL_FBO
  555. class QCP_LIB_DECL QCPPaintBufferGlFbo : public QCPAbstractPaintBuffer
  556. {
  557. public:
  558. explicit QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer<QOpenGLContext> glContext, QWeakPointer<QOpenGLPaintDevice> glPaintDevice);
  559. virtual ~QCPPaintBufferGlFbo() Q_DECL_OVERRIDE;
  560. // reimplemented virtual methods:
  561. virtual QCPPainter *startPainting() Q_DECL_OVERRIDE;
  562. virtual void donePainting() Q_DECL_OVERRIDE;
  563. virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE;
  564. void clear(const QColor &color) Q_DECL_OVERRIDE;
  565. protected:
  566. // non-property members:
  567. QWeakPointer<QOpenGLContext> mGlContext;
  568. QWeakPointer<QOpenGLPaintDevice> mGlPaintDevice;
  569. QOpenGLFramebufferObject *mGlFrameBuffer;
  570. // reimplemented virtual methods:
  571. virtual void reallocateBuffer() Q_DECL_OVERRIDE;
  572. };
  573. #endif // QCP_OPENGL_FBO
  574. /* end of 'src/paintbuffer.h' */
  575. /* including file 'src/layer.h' */
  576. /* modified 2022-11-06T12:45:56, size 7038 */
  577. class QCP_LIB_DECL QCPLayer : public QObject
  578. {
  579. Q_OBJECT
  580. /// \cond INCLUDE_QPROPERTIES
  581. Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
  582. Q_PROPERTY(QString name READ name)
  583. Q_PROPERTY(int index READ index)
  584. Q_PROPERTY(QList<QCPLayerable*> children READ children)
  585. Q_PROPERTY(bool visible READ visible WRITE setVisible)
  586. Q_PROPERTY(LayerMode mode READ mode WRITE setMode)
  587. /// \endcond
  588. public:
  589. /*!
  590. Defines the different rendering modes of a layer. Depending on the mode, certain layers can be
  591. replotted individually, without the need to replot (possibly complex) layerables on other
  592. layers.
  593. \see setMode
  594. */
  595. enum LayerMode { lmLogical ///< Layer is used only for rendering order, and shares paint buffer with all other adjacent logical layers.
  596. ,lmBuffered ///< Layer has its own paint buffer and may be replotted individually (see \ref replot).
  597. };
  598. Q_ENUMS(LayerMode)
  599. QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
  600. virtual ~QCPLayer();
  601. // getters:
  602. QCustomPlot *parentPlot() const { return mParentPlot; }
  603. QString name() const { return mName; }
  604. int index() const { return mIndex; }
  605. QList<QCPLayerable*> children() const { return mChildren; }
  606. bool visible() const { return mVisible; }
  607. LayerMode mode() const { return mMode; }
  608. // setters:
  609. void setVisible(bool visible);
  610. void setMode(LayerMode mode);
  611. // non-virtual methods:
  612. void replot();
  613. protected:
  614. // property members:
  615. QCustomPlot *mParentPlot;
  616. QString mName;
  617. int mIndex;
  618. QList<QCPLayerable*> mChildren;
  619. bool mVisible;
  620. LayerMode mMode;
  621. // non-property members:
  622. QWeakPointer<QCPAbstractPaintBuffer> mPaintBuffer;
  623. // non-virtual methods:
  624. void draw(QCPPainter *painter);
  625. void drawToPaintBuffer();
  626. void addChild(QCPLayerable *layerable, bool prepend);
  627. void removeChild(QCPLayerable *layerable);
  628. private:
  629. Q_DISABLE_COPY(QCPLayer)
  630. friend class QCustomPlot;
  631. friend class QCPLayerable;
  632. };
  633. Q_DECLARE_METATYPE(QCPLayer::LayerMode)
  634. class QCP_LIB_DECL QCPLayerable : public QObject
  635. {
  636. Q_OBJECT
  637. /// \cond INCLUDE_QPROPERTIES
  638. Q_PROPERTY(bool visible READ visible WRITE setVisible)
  639. Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
  640. Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable)
  641. Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged)
  642. Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased)
  643. /// \endcond
  644. public:
  645. QCPLayerable(QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=nullptr);
  646. virtual ~QCPLayerable();
  647. // getters:
  648. bool visible() const { return mVisible; }
  649. QCustomPlot *parentPlot() const { return mParentPlot; }
  650. QCPLayerable *parentLayerable() const { return mParentLayerable.data(); }
  651. QCPLayer *layer() const { return mLayer; }
  652. bool antialiased() const { return mAntialiased; }
  653. // setters:
  654. void setVisible(bool on);
  655. Q_SLOT bool setLayer(QCPLayer *layer);
  656. bool setLayer(const QString &layerName);
  657. void setAntialiased(bool enabled);
  658. // introduced virtual methods:
  659. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const;
  660. // non-property methods:
  661. bool realVisibility() const;
  662. signals:
  663. void layerChanged(QCPLayer *newLayer);
  664. protected:
  665. // property members:
  666. bool mVisible;
  667. QCustomPlot *mParentPlot;
  668. QPointer<QCPLayerable> mParentLayerable;
  669. QCPLayer *mLayer;
  670. bool mAntialiased;
  671. // introduced virtual methods:
  672. virtual void parentPlotInitialized(QCustomPlot *parentPlot);
  673. virtual QCP::Interaction selectionCategory() const;
  674. virtual QRect clipRect() const;
  675. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
  676. virtual void draw(QCPPainter *painter) = 0;
  677. // selection events:
  678. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
  679. virtual void deselectEvent(bool *selectionStateChanged);
  680. // low-level mouse events:
  681. virtual void mousePressEvent(QMouseEvent *event, const QVariant &details);
  682. virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos);
  683. virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos);
  684. virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details);
  685. virtual void wheelEvent(QWheelEvent *event);
  686. // non-property methods:
  687. void initializeParentPlot(QCustomPlot *parentPlot);
  688. void setParentLayerable(QCPLayerable* parentLayerable);
  689. bool moveToLayer(QCPLayer *layer, bool prepend);
  690. void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
  691. private:
  692. Q_DISABLE_COPY(QCPLayerable)
  693. friend class QCustomPlot;
  694. friend class QCPLayer;
  695. friend class QCPAxisRect;
  696. };
  697. /* end of 'src/layer.h' */
  698. /* including file 'src/axis/range.h' */
  699. /* modified 2022-11-06T12:45:56, size 5280 */
  700. class QCP_LIB_DECL QCPRange
  701. {
  702. public:
  703. double lower, upper;
  704. QCPRange();
  705. QCPRange(double lower, double upper);
  706. bool operator==(const QCPRange& other) const { return lower == other.lower && upper == other.upper; }
  707. bool operator!=(const QCPRange& other) const { return !(*this == other); }
  708. QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; }
  709. QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; }
  710. QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; }
  711. QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; }
  712. friend inline const QCPRange operator+(const QCPRange&, double);
  713. friend inline const QCPRange operator+(double, const QCPRange&);
  714. friend inline const QCPRange operator-(const QCPRange& range, double value);
  715. friend inline const QCPRange operator*(const QCPRange& range, double value);
  716. friend inline const QCPRange operator*(double value, const QCPRange& range);
  717. friend inline const QCPRange operator/(const QCPRange& range, double value);
  718. double size() const { return upper-lower; }
  719. double center() const { return (upper+lower)*0.5; }
  720. void normalize() { if (lower > upper) qSwap(lower, upper); }
  721. void expand(const QCPRange &otherRange);
  722. void expand(double includeCoord);
  723. QCPRange expanded(const QCPRange &otherRange) const;
  724. QCPRange expanded(double includeCoord) const;
  725. QCPRange bounded(double lowerBound, double upperBound) const;
  726. QCPRange sanitizedForLogScale() const;
  727. QCPRange sanitizedForLinScale() const;
  728. bool contains(double value) const { return value >= lower && value <= upper; }
  729. static bool validRange(double lower, double upper);
  730. static bool validRange(const QCPRange &range);
  731. static const double minRange;
  732. static const double maxRange;
  733. };
  734. Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
  735. /*! \relates QCPRange
  736. Prints \a range in a human readable format to the qDebug output.
  737. */
  738. inline QDebug operator<< (QDebug d, const QCPRange &range)
  739. {
  740. d.nospace() << "QCPRange(" << range.lower << ", " << range.upper << ")";
  741. return d.space();
  742. }
  743. /*!
  744. Adds \a value to both boundaries of the range.
  745. */
  746. inline const QCPRange operator+(const QCPRange& range, double value)
  747. {
  748. QCPRange result(range);
  749. result += value;
  750. return result;
  751. }
  752. /*!
  753. Adds \a value to both boundaries of the range.
  754. */
  755. inline const QCPRange operator+(double value, const QCPRange& range)
  756. {
  757. QCPRange result(range);
  758. result += value;
  759. return result;
  760. }
  761. /*!
  762. Subtracts \a value from both boundaries of the range.
  763. */
  764. inline const QCPRange operator-(const QCPRange& range, double value)
  765. {
  766. QCPRange result(range);
  767. result -= value;
  768. return result;
  769. }
  770. /*!
  771. Multiplies both boundaries of the range by \a value.
  772. */
  773. inline const QCPRange operator*(const QCPRange& range, double value)
  774. {
  775. QCPRange result(range);
  776. result *= value;
  777. return result;
  778. }
  779. /*!
  780. Multiplies both boundaries of the range by \a value.
  781. */
  782. inline const QCPRange operator*(double value, const QCPRange& range)
  783. {
  784. QCPRange result(range);
  785. result *= value;
  786. return result;
  787. }
  788. /*!
  789. Divides both boundaries of the range by \a value.
  790. */
  791. inline const QCPRange operator/(const QCPRange& range, double value)
  792. {
  793. QCPRange result(range);
  794. result /= value;
  795. return result;
  796. }
  797. /* end of 'src/axis/range.h' */
  798. /* including file 'src/selection.h' */
  799. /* modified 2022-11-06T12:45:56, size 8569 */
  800. class QCP_LIB_DECL QCPDataRange
  801. {
  802. public:
  803. QCPDataRange();
  804. QCPDataRange(int begin, int end);
  805. bool operator==(const QCPDataRange& other) const { return mBegin == other.mBegin && mEnd == other.mEnd; }
  806. bool operator!=(const QCPDataRange& other) const { return !(*this == other); }
  807. // getters:
  808. int begin() const { return mBegin; }
  809. int end() const { return mEnd; }
  810. int size() const { return mEnd-mBegin; }
  811. int length() const { return size(); }
  812. // setters:
  813. void setBegin(int begin) { mBegin = begin; }
  814. void setEnd(int end) { mEnd = end; }
  815. // non-property methods:
  816. bool isValid() const { return (mEnd >= mBegin) && (mBegin >= 0); }
  817. bool isEmpty() const { return length() == 0; }
  818. QCPDataRange bounded(const QCPDataRange &other) const;
  819. QCPDataRange expanded(const QCPDataRange &other) const;
  820. QCPDataRange intersection(const QCPDataRange &other) const;
  821. QCPDataRange adjusted(int changeBegin, int changeEnd) const { return QCPDataRange(mBegin+changeBegin, mEnd+changeEnd); }
  822. bool intersects(const QCPDataRange &other) const;
  823. bool contains(const QCPDataRange &other) const;
  824. private:
  825. // property members:
  826. int mBegin, mEnd;
  827. };
  828. Q_DECLARE_TYPEINFO(QCPDataRange, Q_MOVABLE_TYPE);
  829. class QCP_LIB_DECL QCPDataSelection
  830. {
  831. public:
  832. explicit QCPDataSelection();
  833. explicit QCPDataSelection(const QCPDataRange &range);
  834. bool operator==(const QCPDataSelection& other) const;
  835. bool operator!=(const QCPDataSelection& other) const { return !(*this == other); }
  836. QCPDataSelection &operator+=(const QCPDataSelection& other);
  837. QCPDataSelection &operator+=(const QCPDataRange& other);
  838. QCPDataSelection &operator-=(const QCPDataSelection& other);
  839. QCPDataSelection &operator-=(const QCPDataRange& other);
  840. friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b);
  841. friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b);
  842. friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b);
  843. friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b);
  844. friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b);
  845. friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b);
  846. friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b);
  847. friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b);
  848. // getters:
  849. int dataRangeCount() const { return mDataRanges.size(); }
  850. int dataPointCount() const;
  851. QCPDataRange dataRange(int index=0) const;
  852. QList<QCPDataRange> dataRanges() const { return mDataRanges; }
  853. QCPDataRange span() const;
  854. // non-property methods:
  855. void addDataRange(const QCPDataRange &dataRange, bool simplify=true);
  856. void clear();
  857. bool isEmpty() const { return mDataRanges.isEmpty(); }
  858. void simplify();
  859. void enforceType(QCP::SelectionType type);
  860. bool contains(const QCPDataSelection &other) const;
  861. QCPDataSelection intersection(const QCPDataRange &other) const;
  862. QCPDataSelection intersection(const QCPDataSelection &other) const;
  863. QCPDataSelection inverse(const QCPDataRange &outerRange) const;
  864. private:
  865. // property members:
  866. QList<QCPDataRange> mDataRanges;
  867. inline static bool lessThanDataRangeBegin(const QCPDataRange &a, const QCPDataRange &b) { return a.begin() < b.begin(); }
  868. };
  869. Q_DECLARE_METATYPE(QCPDataSelection)
  870. /*!
  871. Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b.
  872. The resulting data selection is already simplified (see \ref QCPDataSelection::simplify).
  873. */
  874. inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b)
  875. {
  876. QCPDataSelection result(a);
  877. result += b;
  878. return result;
  879. }
  880. /*!
  881. Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b.
  882. The resulting data selection is already simplified (see \ref QCPDataSelection::simplify).
  883. */
  884. inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b)
  885. {
  886. QCPDataSelection result(a);
  887. result += b;
  888. return result;
  889. }
  890. /*!
  891. Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b.
  892. The resulting data selection is already simplified (see \ref QCPDataSelection::simplify).
  893. */
  894. inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b)
  895. {
  896. QCPDataSelection result(a);
  897. result += b;
  898. return result;
  899. }
  900. /*!
  901. Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b.
  902. The resulting data selection is already simplified (see \ref QCPDataSelection::simplify).
  903. */
  904. inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b)
  905. {
  906. QCPDataSelection result(a);
  907. result += b;
  908. return result;
  909. }
  910. /*!
  911. Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b.
  912. */
  913. inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b)
  914. {
  915. QCPDataSelection result(a);
  916. result -= b;
  917. return result;
  918. }
  919. /*!
  920. Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b.
  921. */
  922. inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b)
  923. {
  924. QCPDataSelection result(a);
  925. result -= b;
  926. return result;
  927. }
  928. /*!
  929. Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b.
  930. */
  931. inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b)
  932. {
  933. QCPDataSelection result(a);
  934. result -= b;
  935. return result;
  936. }
  937. /*!
  938. Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b.
  939. */
  940. inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b)
  941. {
  942. QCPDataSelection result(a);
  943. result -= b;
  944. return result;
  945. }
  946. /*! \relates QCPDataRange
  947. Prints \a dataRange in a human readable format to the qDebug output.
  948. */
  949. inline QDebug operator<< (QDebug d, const QCPDataRange &dataRange)
  950. {
  951. d.nospace() << "QCPDataRange(" << dataRange.begin() << ", " << dataRange.end() << ")";
  952. return d;
  953. }
  954. /*! \relates QCPDataSelection
  955. Prints \a selection in a human readable format to the qDebug output.
  956. */
  957. inline QDebug operator<< (QDebug d, const QCPDataSelection &selection)
  958. {
  959. d.nospace() << "QCPDataSelection(";
  960. for (int i=0; i<selection.dataRangeCount(); ++i)
  961. {
  962. if (i != 0)
  963. d << ", ";
  964. d << selection.dataRange(i);
  965. }
  966. d << ")";
  967. return d;
  968. }
  969. /* end of 'src/selection.h' */
  970. /* including file 'src/selectionrect.h' */
  971. /* modified 2022-11-06T12:45:56, size 3354 */
  972. class QCP_LIB_DECL QCPSelectionRect : public QCPLayerable
  973. {
  974. Q_OBJECT
  975. public:
  976. explicit QCPSelectionRect(QCustomPlot *parentPlot);
  977. virtual ~QCPSelectionRect() Q_DECL_OVERRIDE;
  978. // getters:
  979. QRect rect() const { return mRect; }
  980. QCPRange range(const QCPAxis *axis) const;
  981. QPen pen() const { return mPen; }
  982. QBrush brush() const { return mBrush; }
  983. bool isActive() const { return mActive; }
  984. // setters:
  985. void setPen(const QPen &pen);
  986. void setBrush(const QBrush &brush);
  987. // non-property methods:
  988. Q_SLOT void cancel();
  989. signals:
  990. void started(QMouseEvent *event);
  991. void changed(const QRect &rect, QMouseEvent *event);
  992. void canceled(const QRect &rect, QInputEvent *event);
  993. void accepted(const QRect &rect, QMouseEvent *event);
  994. protected:
  995. // property members:
  996. QRect mRect;
  997. QPen mPen;
  998. QBrush mBrush;
  999. // non-property members:
  1000. bool mActive;
  1001. // introduced virtual methods:
  1002. virtual void startSelection(QMouseEvent *event);
  1003. virtual void moveSelection(QMouseEvent *event);
  1004. virtual void endSelection(QMouseEvent *event);
  1005. virtual void keyPressEvent(QKeyEvent *event);
  1006. // reimplemented virtual methods
  1007. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  1008. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  1009. friend class QCustomPlot;
  1010. };
  1011. /* end of 'src/selectionrect.h' */
  1012. /* including file 'src/layout.h' */
  1013. /* modified 2022-11-06T12:45:56, size 14279 */
  1014. class QCP_LIB_DECL QCPMarginGroup : public QObject
  1015. {
  1016. Q_OBJECT
  1017. public:
  1018. explicit QCPMarginGroup(QCustomPlot *parentPlot);
  1019. virtual ~QCPMarginGroup();
  1020. // non-virtual methods:
  1021. QList<QCPLayoutElement*> elements(QCP::MarginSide side) const { return mChildren.value(side); }
  1022. bool isEmpty() const;
  1023. void clear();
  1024. protected:
  1025. // non-property members:
  1026. QCustomPlot *mParentPlot;
  1027. QHash<QCP::MarginSide, QList<QCPLayoutElement*> > mChildren;
  1028. // introduced virtual methods:
  1029. virtual int commonMargin(QCP::MarginSide side) const;
  1030. // non-virtual methods:
  1031. void addChild(QCP::MarginSide side, QCPLayoutElement *element);
  1032. void removeChild(QCP::MarginSide side, QCPLayoutElement *element);
  1033. private:
  1034. Q_DISABLE_COPY(QCPMarginGroup)
  1035. friend class QCPLayoutElement;
  1036. };
  1037. class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable
  1038. {
  1039. Q_OBJECT
  1040. /// \cond INCLUDE_QPROPERTIES
  1041. Q_PROPERTY(QCPLayout* layout READ layout)
  1042. Q_PROPERTY(QRect rect READ rect)
  1043. Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect)
  1044. Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
  1045. Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
  1046. Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
  1047. Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
  1048. Q_PROPERTY(SizeConstraintRect sizeConstraintRect READ sizeConstraintRect WRITE setSizeConstraintRect)
  1049. /// \endcond
  1050. public:
  1051. /*!
  1052. Defines the phases of the update process, that happens just before a replot. At each phase,
  1053. \ref update is called with the according UpdatePhase value.
  1054. */
  1055. enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout
  1056. ,upMargins ///< Phase in which the margins are calculated and set
  1057. ,upLayout ///< Final phase in which the layout system places the rects of the elements
  1058. };
  1059. Q_ENUMS(UpdatePhase)
  1060. /*!
  1061. Defines to which rect of a layout element the size constraints that can be set via \ref
  1062. setMinimumSize and \ref setMaximumSize apply. The outer rect (\ref outerRect) includes the
  1063. margins (e.g. in the case of a QCPAxisRect the axis labels), whereas the inner rect (\ref rect)
  1064. does not.
  1065. \see setSizeConstraintRect
  1066. */
  1067. enum SizeConstraintRect { scrInnerRect ///< Minimum/Maximum size constraints apply to inner rect
  1068. , scrOuterRect ///< Minimum/Maximum size constraints apply to outer rect, thus include layout element margins
  1069. };
  1070. Q_ENUMS(SizeConstraintRect)
  1071. explicit QCPLayoutElement(QCustomPlot *parentPlot=nullptr);
  1072. virtual ~QCPLayoutElement() Q_DECL_OVERRIDE;
  1073. // getters:
  1074. QCPLayout *layout() const { return mParentLayout; }
  1075. QRect rect() const { return mRect; }
  1076. QRect outerRect() const { return mOuterRect; }
  1077. QMargins margins() const { return mMargins; }
  1078. QMargins minimumMargins() const { return mMinimumMargins; }
  1079. QCP::MarginSides autoMargins() const { return mAutoMargins; }
  1080. QSize minimumSize() const { return mMinimumSize; }
  1081. QSize maximumSize() const { return mMaximumSize; }
  1082. SizeConstraintRect sizeConstraintRect() const { return mSizeConstraintRect; }
  1083. QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, nullptr); }
  1084. QHash<QCP::MarginSide, QCPMarginGroup*> marginGroups() const { return mMarginGroups; }
  1085. // setters:
  1086. void setOuterRect(const QRect &rect);
  1087. void setMargins(const QMargins &margins);
  1088. void setMinimumMargins(const QMargins &margins);
  1089. void setAutoMargins(QCP::MarginSides sides);
  1090. void setMinimumSize(const QSize &size);
  1091. void setMinimumSize(int width, int height);
  1092. void setMaximumSize(const QSize &size);
  1093. void setMaximumSize(int width, int height);
  1094. void setSizeConstraintRect(SizeConstraintRect constraintRect);
  1095. void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group);
  1096. // introduced virtual methods:
  1097. virtual void update(UpdatePhase phase);
  1098. virtual QSize minimumOuterSizeHint() const;
  1099. virtual QSize maximumOuterSizeHint() const;
  1100. virtual QList<QCPLayoutElement*> elements(bool recursive) const;
  1101. // reimplemented virtual methods:
  1102. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  1103. protected:
  1104. // property members:
  1105. QCPLayout *mParentLayout;
  1106. QSize mMinimumSize, mMaximumSize;
  1107. SizeConstraintRect mSizeConstraintRect;
  1108. QRect mRect, mOuterRect;
  1109. QMargins mMargins, mMinimumMargins;
  1110. QCP::MarginSides mAutoMargins;
  1111. QHash<QCP::MarginSide, QCPMarginGroup*> mMarginGroups;
  1112. // introduced virtual methods:
  1113. virtual int calculateAutoMargin(QCP::MarginSide side);
  1114. virtual void layoutChanged();
  1115. // reimplemented virtual methods:
  1116. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE { Q_UNUSED(painter) }
  1117. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE { Q_UNUSED(painter) }
  1118. virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE;
  1119. private:
  1120. Q_DISABLE_COPY(QCPLayoutElement)
  1121. friend class QCustomPlot;
  1122. friend class QCPLayout;
  1123. friend class QCPMarginGroup;
  1124. };
  1125. Q_DECLARE_METATYPE(QCPLayoutElement::UpdatePhase)
  1126. class QCP_LIB_DECL QCPLayout : public QCPLayoutElement
  1127. {
  1128. Q_OBJECT
  1129. public:
  1130. explicit QCPLayout();
  1131. // reimplemented virtual methods:
  1132. virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE;
  1133. virtual QList<QCPLayoutElement*> elements(bool recursive) const Q_DECL_OVERRIDE;
  1134. // introduced virtual methods:
  1135. virtual int elementCount() const = 0;
  1136. virtual QCPLayoutElement* elementAt(int index) const = 0;
  1137. virtual QCPLayoutElement* takeAt(int index) = 0;
  1138. virtual bool take(QCPLayoutElement* element) = 0;
  1139. virtual void simplify();
  1140. // non-virtual methods:
  1141. bool removeAt(int index);
  1142. bool remove(QCPLayoutElement* element);
  1143. void clear();
  1144. protected:
  1145. // introduced virtual methods:
  1146. virtual void updateLayout();
  1147. // non-virtual methods:
  1148. void sizeConstraintsChanged() const;
  1149. void adoptElement(QCPLayoutElement *el);
  1150. void releaseElement(QCPLayoutElement *el);
  1151. QVector<int> getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes, QVector<double> stretchFactors, int totalSize) const;
  1152. static QSize getFinalMinimumOuterSize(const QCPLayoutElement *el);
  1153. static QSize getFinalMaximumOuterSize(const QCPLayoutElement *el);
  1154. private:
  1155. Q_DISABLE_COPY(QCPLayout)
  1156. friend class QCPLayoutElement;
  1157. };
  1158. class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout
  1159. {
  1160. Q_OBJECT
  1161. /// \cond INCLUDE_QPROPERTIES
  1162. Q_PROPERTY(int rowCount READ rowCount)
  1163. Q_PROPERTY(int columnCount READ columnCount)
  1164. Q_PROPERTY(QList<double> columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors)
  1165. Q_PROPERTY(QList<double> rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors)
  1166. Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
  1167. Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
  1168. Q_PROPERTY(FillOrder fillOrder READ fillOrder WRITE setFillOrder)
  1169. Q_PROPERTY(int wrap READ wrap WRITE setWrap)
  1170. /// \endcond
  1171. public:
  1172. /*!
  1173. Defines in which direction the grid is filled when using \ref addElement(QCPLayoutElement*).
  1174. The column/row at which wrapping into the next row/column occurs can be specified with \ref
  1175. setWrap.
  1176. \see setFillOrder
  1177. */
  1178. enum FillOrder { foRowsFirst ///< Rows are filled first, and a new element is wrapped to the next column if the row count would exceed \ref setWrap.
  1179. ,foColumnsFirst ///< Columns are filled first, and a new element is wrapped to the next row if the column count would exceed \ref setWrap.
  1180. };
  1181. Q_ENUMS(FillOrder)
  1182. explicit QCPLayoutGrid();
  1183. virtual ~QCPLayoutGrid() Q_DECL_OVERRIDE;
  1184. // getters:
  1185. int rowCount() const { return mElements.size(); }
  1186. int columnCount() const { return mElements.size() > 0 ? mElements.first().size() : 0; }
  1187. QList<double> columnStretchFactors() const { return mColumnStretchFactors; }
  1188. QList<double> rowStretchFactors() const { return mRowStretchFactors; }
  1189. int columnSpacing() const { return mColumnSpacing; }
  1190. int rowSpacing() const { return mRowSpacing; }
  1191. int wrap() const { return mWrap; }
  1192. FillOrder fillOrder() const { return mFillOrder; }
  1193. // setters:
  1194. void setColumnStretchFactor(int column, double factor);
  1195. void setColumnStretchFactors(const QList<double> &factors);
  1196. void setRowStretchFactor(int row, double factor);
  1197. void setRowStretchFactors(const QList<double> &factors);
  1198. void setColumnSpacing(int pixels);
  1199. void setRowSpacing(int pixels);
  1200. void setWrap(int count);
  1201. void setFillOrder(FillOrder order, bool rearrange=true);
  1202. // reimplemented virtual methods:
  1203. virtual void updateLayout() Q_DECL_OVERRIDE;
  1204. virtual int elementCount() const Q_DECL_OVERRIDE { return rowCount()*columnCount(); }
  1205. virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE;
  1206. virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE;
  1207. virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE;
  1208. virtual QList<QCPLayoutElement*> elements(bool recursive) const Q_DECL_OVERRIDE;
  1209. virtual void simplify() Q_DECL_OVERRIDE;
  1210. virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE;
  1211. virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE;
  1212. // non-virtual methods:
  1213. QCPLayoutElement *element(int row, int column) const;
  1214. bool addElement(int row, int column, QCPLayoutElement *element);
  1215. bool addElement(QCPLayoutElement *element);
  1216. bool hasElement(int row, int column);
  1217. void expandTo(int newRowCount, int newColumnCount);
  1218. void insertRow(int newIndex);
  1219. void insertColumn(int newIndex);
  1220. int rowColToIndex(int row, int column) const;
  1221. void indexToRowCol(int index, int &row, int &column) const;
  1222. protected:
  1223. // property members:
  1224. QList<QList<QCPLayoutElement*> > mElements;
  1225. QList<double> mColumnStretchFactors;
  1226. QList<double> mRowStretchFactors;
  1227. int mColumnSpacing, mRowSpacing;
  1228. int mWrap;
  1229. FillOrder mFillOrder;
  1230. // non-virtual methods:
  1231. void getMinimumRowColSizes(QVector<int> *minColWidths, QVector<int> *minRowHeights) const;
  1232. void getMaximumRowColSizes(QVector<int> *maxColWidths, QVector<int> *maxRowHeights) const;
  1233. private:
  1234. Q_DISABLE_COPY(QCPLayoutGrid)
  1235. };
  1236. Q_DECLARE_METATYPE(QCPLayoutGrid::FillOrder)
  1237. class QCP_LIB_DECL QCPLayoutInset : public QCPLayout
  1238. {
  1239. Q_OBJECT
  1240. public:
  1241. /*!
  1242. Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset.
  1243. */
  1244. enum InsetPlacement { ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect
  1245. ,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment
  1246. };
  1247. Q_ENUMS(InsetPlacement)
  1248. explicit QCPLayoutInset();
  1249. virtual ~QCPLayoutInset() Q_DECL_OVERRIDE;
  1250. // getters:
  1251. InsetPlacement insetPlacement(int index) const;
  1252. Qt::Alignment insetAlignment(int index) const;
  1253. QRectF insetRect(int index) const;
  1254. // setters:
  1255. void setInsetPlacement(int index, InsetPlacement placement);
  1256. void setInsetAlignment(int index, Qt::Alignment alignment);
  1257. void setInsetRect(int index, const QRectF &rect);
  1258. // reimplemented virtual methods:
  1259. virtual void updateLayout() Q_DECL_OVERRIDE;
  1260. virtual int elementCount() const Q_DECL_OVERRIDE;
  1261. virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE;
  1262. virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE;
  1263. virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE;
  1264. virtual void simplify() Q_DECL_OVERRIDE {}
  1265. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  1266. // non-virtual methods:
  1267. void addElement(QCPLayoutElement *element, Qt::Alignment alignment);
  1268. void addElement(QCPLayoutElement *element, const QRectF &rect);
  1269. protected:
  1270. // property members:
  1271. QList<QCPLayoutElement*> mElements;
  1272. QList<InsetPlacement> mInsetPlacement;
  1273. QList<Qt::Alignment> mInsetAlignment;
  1274. QList<QRectF> mInsetRect;
  1275. private:
  1276. Q_DISABLE_COPY(QCPLayoutInset)
  1277. };
  1278. Q_DECLARE_METATYPE(QCPLayoutInset::InsetPlacement)
  1279. /* end of 'src/layout.h' */
  1280. /* including file 'src/lineending.h' */
  1281. /* modified 2022-11-06T12:45:56, size 4426 */
  1282. class QCP_LIB_DECL QCPLineEnding
  1283. {
  1284. Q_GADGET
  1285. public:
  1286. /*!
  1287. Defines the type of ending decoration for line-like items, e.g. an arrow.
  1288. \image html QCPLineEnding.png
  1289. The width and length of these decorations can be controlled with the functions \ref setWidth
  1290. and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only
  1291. support a width, the length property is ignored.
  1292. \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding
  1293. */
  1294. enum EndingStyle { esNone ///< No ending decoration
  1295. ,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle)
  1296. ,esSpikeArrow ///< A filled arrow head with an indented back
  1297. ,esLineArrow ///< A non-filled arrow head with open back
  1298. ,esDisc ///< A filled circle
  1299. ,esSquare ///< A filled square
  1300. ,esDiamond ///< A filled diamond (45 degrees rotated square)
  1301. ,esBar ///< A bar perpendicular to the line
  1302. ,esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted)
  1303. ,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength)
  1304. };
  1305. Q_ENUMS(EndingStyle)
  1306. QCPLineEnding();
  1307. QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false);
  1308. // getters:
  1309. EndingStyle style() const { return mStyle; }
  1310. double width() const { return mWidth; }
  1311. double length() const { return mLength; }
  1312. bool inverted() const { return mInverted; }
  1313. // setters:
  1314. void setStyle(EndingStyle style);
  1315. void setWidth(double width);
  1316. void setLength(double length);
  1317. void setInverted(bool inverted);
  1318. // non-property methods:
  1319. double boundingDistance() const;
  1320. double realLength() const;
  1321. void draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const;
  1322. void draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const;
  1323. protected:
  1324. // property members:
  1325. EndingStyle mStyle;
  1326. double mWidth, mLength;
  1327. bool mInverted;
  1328. };
  1329. Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE);
  1330. Q_DECLARE_METATYPE(QCPLineEnding::EndingStyle)
  1331. /* end of 'src/lineending.h' */
  1332. /* including file 'src/axis/labelpainter.h' */
  1333. /* modified 2022-11-06T12:45:56, size 7086 */
  1334. class QCPLabelPainterPrivate
  1335. {
  1336. Q_GADGET
  1337. public:
  1338. /*!
  1339. TODO
  1340. */
  1341. enum AnchorMode { amRectangular ///<
  1342. ,amSkewedUpright ///<
  1343. ,amSkewedRotated ///<
  1344. };
  1345. Q_ENUMS(AnchorMode)
  1346. /*!
  1347. TODO
  1348. */
  1349. enum AnchorReferenceType { artNormal ///<
  1350. ,artTangent ///<
  1351. };
  1352. Q_ENUMS(AnchorReferenceType)
  1353. /*!
  1354. TODO
  1355. */
  1356. enum AnchorSide { asLeft ///<
  1357. ,asRight ///<
  1358. ,asTop ///<
  1359. ,asBottom ///<
  1360. ,asTopLeft
  1361. ,asTopRight
  1362. ,asBottomRight
  1363. ,asBottomLeft
  1364. };
  1365. Q_ENUMS(AnchorSide)
  1366. explicit QCPLabelPainterPrivate(QCustomPlot *parentPlot);
  1367. virtual ~QCPLabelPainterPrivate();
  1368. // setters:
  1369. void setAnchorSide(AnchorSide side);
  1370. void setAnchorMode(AnchorMode mode);
  1371. void setAnchorReference(const QPointF &pixelPoint);
  1372. void setAnchorReferenceType(AnchorReferenceType type);
  1373. void setFont(const QFont &font);
  1374. void setColor(const QColor &color);
  1375. void setPadding(int padding);
  1376. void setRotation(double rotation);
  1377. void setSubstituteExponent(bool enabled);
  1378. void setMultiplicationSymbol(QChar symbol);
  1379. void setAbbreviateDecimalPowers(bool enabled);
  1380. void setCacheSize(int labelCount);
  1381. // getters:
  1382. AnchorMode anchorMode() const { return mAnchorMode; }
  1383. AnchorSide anchorSide() const { return mAnchorSide; }
  1384. QPointF anchorReference() const { return mAnchorReference; }
  1385. AnchorReferenceType anchorReferenceType() const { return mAnchorReferenceType; }
  1386. QFont font() const { return mFont; }
  1387. QColor color() const { return mColor; }
  1388. int padding() const { return mPadding; }
  1389. double rotation() const { return mRotation; }
  1390. bool substituteExponent() const { return mSubstituteExponent; }
  1391. QChar multiplicationSymbol() const { return mMultiplicationSymbol; }
  1392. bool abbreviateDecimalPowers() const { return mAbbreviateDecimalPowers; }
  1393. int cacheSize() const;
  1394. //virtual int size() const;
  1395. // non-property methods:
  1396. void drawTickLabel(QCPPainter *painter, const QPointF &tickPos, const QString &text);
  1397. void clearCache();
  1398. // constants that may be used with setMultiplicationSymbol:
  1399. static const QChar SymbolDot;
  1400. static const QChar SymbolCross;
  1401. protected:
  1402. struct CachedLabel
  1403. {
  1404. QPoint offset;
  1405. QPixmap pixmap;
  1406. };
  1407. struct LabelData
  1408. {
  1409. AnchorSide side;
  1410. double rotation; // angle in degrees
  1411. QTransform transform; // the transform about the label anchor which is at (0, 0). Does not contain final absolute x/y positioning on the plot/axis
  1412. QString basePart, expPart, suffixPart;
  1413. QRect baseBounds, expBounds, suffixBounds;
  1414. QRect totalBounds; // is in a coordinate system where label top left is at (0, 0)
  1415. QRect rotatedTotalBounds; // is in a coordinate system where the label anchor is at (0, 0)
  1416. QFont baseFont, expFont;
  1417. QColor color;
  1418. };
  1419. // property members:
  1420. AnchorMode mAnchorMode;
  1421. AnchorSide mAnchorSide;
  1422. QPointF mAnchorReference;
  1423. AnchorReferenceType mAnchorReferenceType;
  1424. QFont mFont;
  1425. QColor mColor;
  1426. int mPadding;
  1427. double mRotation; // this is the rotation applied uniformly to all labels, not the heterogeneous rotation in amCircularRotated mode
  1428. bool mSubstituteExponent;
  1429. QChar mMultiplicationSymbol;
  1430. bool mAbbreviateDecimalPowers;
  1431. // non-property members:
  1432. QCustomPlot *mParentPlot;
  1433. QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters
  1434. QCache<QString, CachedLabel> mLabelCache;
  1435. QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox;
  1436. int mLetterCapHeight, mLetterDescent;
  1437. // introduced virtual methods:
  1438. virtual void drawLabelMaybeCached(QCPPainter *painter, const QFont &font, const QColor &color, const QPointF &pos, AnchorSide side, double rotation, const QString &text);
  1439. virtual QByteArray generateLabelParameterHash() const; // TODO: get rid of this in favor of invalidation flag upon setters?
  1440. // non-virtual methods:
  1441. QPointF getAnchorPos(const QPointF &tickPos);
  1442. void drawText(QCPPainter *painter, const QPointF &pos, const LabelData &labelData) const;
  1443. LabelData getTickLabelData(const QFont &font, const QColor &color, double rotation, AnchorSide side, const QString &text) const;
  1444. void applyAnchorTransform(LabelData &labelData) const;
  1445. //void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const;
  1446. CachedLabel *createCachedLabel(const LabelData &labelData) const;
  1447. QByteArray cacheKey(const QString &text, const QColor &color, double rotation, AnchorSide side) const;
  1448. AnchorSide skewedAnchorSide(const QPointF &tickPos, double sideExpandHorz, double sideExpandVert) const;
  1449. AnchorSide rotationCorrectedSide(AnchorSide side, double rotation) const;
  1450. void analyzeFontMetrics();
  1451. };
  1452. Q_DECLARE_METATYPE(QCPLabelPainterPrivate::AnchorMode)
  1453. Q_DECLARE_METATYPE(QCPLabelPainterPrivate::AnchorSide)
  1454. /* end of 'src/axis/labelpainter.h' */
  1455. /* including file 'src/axis/axisticker.h' */
  1456. /* modified 2022-11-06T12:45:56, size 4230 */
  1457. class QCP_LIB_DECL QCPAxisTicker
  1458. {
  1459. Q_GADGET
  1460. public:
  1461. /*!
  1462. Defines the strategies that the axis ticker may follow when choosing the size of the tick step.
  1463. \see setTickStepStrategy
  1464. */
  1465. enum TickStepStrategy
  1466. {
  1467. tssReadability ///< A nicely readable tick step is prioritized over matching the requested number of ticks (see \ref setTickCount)
  1468. ,tssMeetTickCount ///< Less readable tick steps are allowed which in turn facilitates getting closer to the requested tick count
  1469. };
  1470. Q_ENUMS(TickStepStrategy)
  1471. QCPAxisTicker();
  1472. virtual ~QCPAxisTicker();
  1473. // getters:
  1474. TickStepStrategy tickStepStrategy() const { return mTickStepStrategy; }
  1475. int tickCount() const { return mTickCount; }
  1476. double tickOrigin() const { return mTickOrigin; }
  1477. // setters:
  1478. void setTickStepStrategy(TickStepStrategy strategy);
  1479. void setTickCount(int count);
  1480. void setTickOrigin(double origin);
  1481. // introduced virtual methods:
  1482. virtual void generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector<double> &ticks, QVector<double> *subTicks, QVector<QString> *tickLabels);
  1483. protected:
  1484. // property members:
  1485. TickStepStrategy mTickStepStrategy;
  1486. int mTickCount;
  1487. double mTickOrigin;
  1488. // introduced virtual methods:
  1489. virtual double getTickStep(const QCPRange &range);
  1490. virtual int getSubTickCount(double tickStep);
  1491. virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision);
  1492. virtual QVector<double> createTickVector(double tickStep, const QCPRange &range);
  1493. virtual QVector<double> createSubTickVector(int subTickCount, const QVector<double> &ticks);
  1494. virtual QVector<QString> createLabelVector(const QVector<double> &ticks, const QLocale &locale, QChar formatChar, int precision);
  1495. // non-virtual methods:
  1496. void trimTicks(const QCPRange &range, QVector<double> &ticks, bool keepOneOutlier) const;
  1497. double pickClosest(double target, const QVector<double> &candidates) const;
  1498. double getMantissa(double input, double *magnitude=nullptr) const;
  1499. double cleanMantissa(double input) const;
  1500. private:
  1501. Q_DISABLE_COPY(QCPAxisTicker)
  1502. };
  1503. Q_DECLARE_METATYPE(QCPAxisTicker::TickStepStrategy)
  1504. Q_DECLARE_METATYPE(QSharedPointer<QCPAxisTicker>)
  1505. /* end of 'src/axis/axisticker.h' */
  1506. /* including file 'src/axis/axistickerdatetime.h' */
  1507. /* modified 2022-11-06T12:45:56, size 3600 */
  1508. class QCP_LIB_DECL QCPAxisTickerDateTime : public QCPAxisTicker
  1509. {
  1510. public:
  1511. QCPAxisTickerDateTime();
  1512. // getters:
  1513. QString dateTimeFormat() const { return mDateTimeFormat; }
  1514. Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; }
  1515. # if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
  1516. QTimeZone timeZone() const { return mTimeZone; }
  1517. #endif
  1518. // setters:
  1519. void setDateTimeFormat(const QString &format);
  1520. void setDateTimeSpec(Qt::TimeSpec spec);
  1521. # if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
  1522. void setTimeZone(const QTimeZone &zone);
  1523. # endif
  1524. void setTickOrigin(double origin); // hides base class method but calls baseclass implementation ("using" throws off IDEs and doxygen)
  1525. void setTickOrigin(const QDateTime &origin);
  1526. // static methods:
  1527. static QDateTime keyToDateTime(double key);
  1528. static double dateTimeToKey(const QDateTime &dateTime);
  1529. static double dateTimeToKey(const QDate &date, Qt::TimeSpec timeSpec=Qt::LocalTime);
  1530. protected:
  1531. // property members:
  1532. QString mDateTimeFormat;
  1533. Qt::TimeSpec mDateTimeSpec;
  1534. # if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
  1535. QTimeZone mTimeZone;
  1536. # endif
  1537. // non-property members:
  1538. enum DateStrategy {dsNone, dsUniformTimeInDay, dsUniformDayInMonth} mDateStrategy;
  1539. // reimplemented virtual methods:
  1540. virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE;
  1541. virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE;
  1542. virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE;
  1543. virtual QVector<double> createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE;
  1544. };
  1545. /* end of 'src/axis/axistickerdatetime.h' */
  1546. /* including file 'src/axis/axistickertime.h' */
  1547. /* modified 2022-11-06T12:45:56, size 3542 */
  1548. class QCP_LIB_DECL QCPAxisTickerTime : public QCPAxisTicker
  1549. {
  1550. Q_GADGET
  1551. public:
  1552. /*!
  1553. Defines the logical units in which fractions of time spans can be expressed.
  1554. \see setFieldWidth, setTimeFormat
  1555. */
  1556. enum TimeUnit { tuMilliseconds ///< Milliseconds, one thousandth of a second (%%z in \ref setTimeFormat)
  1557. ,tuSeconds ///< Seconds (%%s in \ref setTimeFormat)
  1558. ,tuMinutes ///< Minutes (%%m in \ref setTimeFormat)
  1559. ,tuHours ///< Hours (%%h in \ref setTimeFormat)
  1560. ,tuDays ///< Days (%%d in \ref setTimeFormat)
  1561. };
  1562. Q_ENUMS(TimeUnit)
  1563. QCPAxisTickerTime();
  1564. // getters:
  1565. QString timeFormat() const { return mTimeFormat; }
  1566. int fieldWidth(TimeUnit unit) const { return mFieldWidth.value(unit); }
  1567. // setters:
  1568. void setTimeFormat(const QString &format);
  1569. void setFieldWidth(TimeUnit unit, int width);
  1570. protected:
  1571. // property members:
  1572. QString mTimeFormat;
  1573. QHash<TimeUnit, int> mFieldWidth;
  1574. // non-property members:
  1575. TimeUnit mSmallestUnit, mBiggestUnit;
  1576. QHash<TimeUnit, QString> mFormatPattern;
  1577. // reimplemented virtual methods:
  1578. virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE;
  1579. virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE;
  1580. virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE;
  1581. // non-virtual methods:
  1582. void replaceUnit(QString &text, TimeUnit unit, int value) const;
  1583. };
  1584. Q_DECLARE_METATYPE(QCPAxisTickerTime::TimeUnit)
  1585. /* end of 'src/axis/axistickertime.h' */
  1586. /* including file 'src/axis/axistickerfixed.h' */
  1587. /* modified 2022-11-06T12:45:56, size 3308 */
  1588. class QCP_LIB_DECL QCPAxisTickerFixed : public QCPAxisTicker
  1589. {
  1590. Q_GADGET
  1591. public:
  1592. /*!
  1593. Defines how the axis ticker may modify the specified tick step (\ref setTickStep) in order to
  1594. control the number of ticks in the axis range.
  1595. \see setScaleStrategy
  1596. */
  1597. enum ScaleStrategy { ssNone ///< Modifications are not allowed, the specified tick step is absolutely fixed. This might cause a high tick density and overlapping labels if the axis range is zoomed out.
  1598. ,ssMultiples ///< An integer multiple of the specified tick step is allowed. The used factor follows the base class properties of \ref setTickStepStrategy and \ref setTickCount.
  1599. ,ssPowers ///< An integer power of the specified tick step is allowed.
  1600. };
  1601. Q_ENUMS(ScaleStrategy)
  1602. QCPAxisTickerFixed();
  1603. // getters:
  1604. double tickStep() const { return mTickStep; }
  1605. ScaleStrategy scaleStrategy() const { return mScaleStrategy; }
  1606. // setters:
  1607. void setTickStep(double step);
  1608. void setScaleStrategy(ScaleStrategy strategy);
  1609. protected:
  1610. // property members:
  1611. double mTickStep;
  1612. ScaleStrategy mScaleStrategy;
  1613. // reimplemented virtual methods:
  1614. virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE;
  1615. };
  1616. Q_DECLARE_METATYPE(QCPAxisTickerFixed::ScaleStrategy)
  1617. /* end of 'src/axis/axistickerfixed.h' */
  1618. /* including file 'src/axis/axistickertext.h' */
  1619. /* modified 2022-11-06T12:45:56, size 3090 */
  1620. class QCP_LIB_DECL QCPAxisTickerText : public QCPAxisTicker
  1621. {
  1622. public:
  1623. QCPAxisTickerText();
  1624. // getters:
  1625. QMap<double, QString> &ticks() { return mTicks; }
  1626. int subTickCount() const { return mSubTickCount; }
  1627. // setters:
  1628. void setTicks(const QMap<double, QString> &ticks);
  1629. void setTicks(const QVector<double> &positions, const QVector<QString> &labels);
  1630. void setSubTickCount(int subTicks);
  1631. // non-virtual methods:
  1632. void clear();
  1633. void addTick(double position, const QString &label);
  1634. void addTicks(const QMap<double, QString> &ticks);
  1635. void addTicks(const QVector<double> &positions, const QVector<QString> &labels);
  1636. protected:
  1637. // property members:
  1638. QMap<double, QString> mTicks;
  1639. int mSubTickCount;
  1640. // reimplemented virtual methods:
  1641. virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE;
  1642. virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE;
  1643. virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE;
  1644. virtual QVector<double> createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE;
  1645. };
  1646. /* end of 'src/axis/axistickertext.h' */
  1647. /* including file 'src/axis/axistickerpi.h' */
  1648. /* modified 2022-11-06T12:45:56, size 3911 */
  1649. class QCP_LIB_DECL QCPAxisTickerPi : public QCPAxisTicker
  1650. {
  1651. Q_GADGET
  1652. public:
  1653. /*!
  1654. Defines how fractions should be displayed in tick labels.
  1655. \see setFractionStyle
  1656. */
  1657. enum FractionStyle { fsFloatingPoint ///< Fractions are displayed as regular decimal floating point numbers, e.g. "0.25" or "0.125".
  1658. ,fsAsciiFractions ///< Fractions are written as rationals using ASCII characters only, e.g. "1/4" or "1/8"
  1659. ,fsUnicodeFractions ///< Fractions are written using sub- and superscript UTF-8 digits and the fraction symbol.
  1660. };
  1661. Q_ENUMS(FractionStyle)
  1662. QCPAxisTickerPi();
  1663. // getters:
  1664. QString piSymbol() const { return mPiSymbol; }
  1665. double piValue() const { return mPiValue; }
  1666. bool periodicity() const { return mPeriodicity; }
  1667. FractionStyle fractionStyle() const { return mFractionStyle; }
  1668. // setters:
  1669. void setPiSymbol(QString symbol);
  1670. void setPiValue(double pi);
  1671. void setPeriodicity(int multiplesOfPi);
  1672. void setFractionStyle(FractionStyle style);
  1673. protected:
  1674. // property members:
  1675. QString mPiSymbol;
  1676. double mPiValue;
  1677. int mPeriodicity;
  1678. FractionStyle mFractionStyle;
  1679. // non-property members:
  1680. double mPiTickStep; // size of one tick step in units of mPiValue
  1681. // reimplemented virtual methods:
  1682. virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE;
  1683. virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE;
  1684. virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE;
  1685. // non-virtual methods:
  1686. void simplifyFraction(int &numerator, int &denominator) const;
  1687. QString fractionToString(int numerator, int denominator) const;
  1688. QString unicodeFraction(int numerator, int denominator) const;
  1689. QString unicodeSuperscript(int number) const;
  1690. QString unicodeSubscript(int number) const;
  1691. };
  1692. Q_DECLARE_METATYPE(QCPAxisTickerPi::FractionStyle)
  1693. /* end of 'src/axis/axistickerpi.h' */
  1694. /* including file 'src/axis/axistickerlog.h' */
  1695. /* modified 2022-11-06T12:45:56, size 2594 */
  1696. class QCP_LIB_DECL QCPAxisTickerLog : public QCPAxisTicker
  1697. {
  1698. public:
  1699. QCPAxisTickerLog();
  1700. // getters:
  1701. double logBase() const { return mLogBase; }
  1702. int subTickCount() const { return mSubTickCount; }
  1703. // setters:
  1704. void setLogBase(double base);
  1705. void setSubTickCount(int subTicks);
  1706. protected:
  1707. // property members:
  1708. double mLogBase;
  1709. int mSubTickCount;
  1710. // non-property members:
  1711. double mLogBaseLnInv;
  1712. // reimplemented virtual methods:
  1713. virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE;
  1714. virtual QVector<double> createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE;
  1715. };
  1716. /* end of 'src/axis/axistickerlog.h' */
  1717. /* including file 'src/axis/axis.h' */
  1718. /* modified 2022-11-06T12:45:56, size 20913 */
  1719. class QCP_LIB_DECL QCPGrid :public QCPLayerable
  1720. {
  1721. Q_OBJECT
  1722. /// \cond INCLUDE_QPROPERTIES
  1723. Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible)
  1724. Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid)
  1725. Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine)
  1726. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  1727. Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen)
  1728. Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen)
  1729. /// \endcond
  1730. public:
  1731. explicit QCPGrid(QCPAxis *parentAxis);
  1732. // getters:
  1733. bool subGridVisible() const { return mSubGridVisible; }
  1734. bool antialiasedSubGrid() const { return mAntialiasedSubGrid; }
  1735. bool antialiasedZeroLine() const { return mAntialiasedZeroLine; }
  1736. QPen pen() const { return mPen; }
  1737. QPen subGridPen() const { return mSubGridPen; }
  1738. QPen zeroLinePen() const { return mZeroLinePen; }
  1739. // setters:
  1740. void setSubGridVisible(bool visible);
  1741. void setAntialiasedSubGrid(bool enabled);
  1742. void setAntialiasedZeroLine(bool enabled);
  1743. void setPen(const QPen &pen);
  1744. void setSubGridPen(const QPen &pen);
  1745. void setZeroLinePen(const QPen &pen);
  1746. protected:
  1747. // property members:
  1748. bool mSubGridVisible;
  1749. bool mAntialiasedSubGrid, mAntialiasedZeroLine;
  1750. QPen mPen, mSubGridPen, mZeroLinePen;
  1751. // non-property members:
  1752. QCPAxis *mParentAxis;
  1753. // reimplemented virtual methods:
  1754. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  1755. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  1756. // non-virtual methods:
  1757. void drawGridLines(QCPPainter *painter) const;
  1758. void drawSubGridLines(QCPPainter *painter) const;
  1759. friend class QCPAxis;
  1760. };
  1761. class QCP_LIB_DECL QCPAxis : public QCPLayerable
  1762. {
  1763. Q_OBJECT
  1764. /// \cond INCLUDE_QPROPERTIES
  1765. Q_PROPERTY(AxisType axisType READ axisType)
  1766. Q_PROPERTY(QCPAxisRect* axisRect READ axisRect)
  1767. Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged)
  1768. Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged)
  1769. Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed)
  1770. Q_PROPERTY(QSharedPointer<QCPAxisTicker> ticker READ ticker WRITE setTicker)
  1771. Q_PROPERTY(bool ticks READ ticks WRITE setTicks)
  1772. Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels)
  1773. Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding)
  1774. Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont)
  1775. Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor)
  1776. Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation)
  1777. Q_PROPERTY(LabelSide tickLabelSide READ tickLabelSide WRITE setTickLabelSide)
  1778. Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat)
  1779. Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision)
  1780. Q_PROPERTY(QVector<double> tickVector READ tickVector)
  1781. Q_PROPERTY(QVector<QString> tickVectorLabels READ tickVectorLabels)
  1782. Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn)
  1783. Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut)
  1784. Q_PROPERTY(bool subTicks READ subTicks WRITE setSubTicks)
  1785. Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn)
  1786. Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut)
  1787. Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen)
  1788. Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen)
  1789. Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen)
  1790. Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont)
  1791. Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor)
  1792. Q_PROPERTY(QString label READ label WRITE setLabel)
  1793. Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding)
  1794. Q_PROPERTY(int padding READ padding WRITE setPadding)
  1795. Q_PROPERTY(int offset READ offset WRITE setOffset)
  1796. Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged)
  1797. Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged)
  1798. Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont)
  1799. Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont)
  1800. Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor)
  1801. Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor)
  1802. Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen)
  1803. Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen)
  1804. Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen)
  1805. Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding)
  1806. Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding)
  1807. Q_PROPERTY(QCPGrid* grid READ grid)
  1808. /// \endcond
  1809. public:
  1810. /*!
  1811. Defines at which side of the axis rect the axis will appear. This also affects how the tick
  1812. marks are drawn, on which side the labels are placed etc.
  1813. */
  1814. enum AxisType { atLeft = 0x01 ///< <tt>0x01</tt> Axis is vertical and on the left side of the axis rect
  1815. ,atRight = 0x02 ///< <tt>0x02</tt> Axis is vertical and on the right side of the axis rect
  1816. ,atTop = 0x04 ///< <tt>0x04</tt> Axis is horizontal and on the top side of the axis rect
  1817. ,atBottom = 0x08 ///< <tt>0x08</tt> Axis is horizontal and on the bottom side of the axis rect
  1818. };
  1819. Q_ENUMS(AxisType)
  1820. Q_FLAGS(AxisTypes)
  1821. Q_DECLARE_FLAGS(AxisTypes, AxisType)
  1822. /*!
  1823. Defines on which side of the axis the tick labels (numbers) shall appear.
  1824. \see setTickLabelSide
  1825. */
  1826. enum LabelSide { lsInside ///< Tick labels will be displayed inside the axis rect and clipped to the inner axis rect
  1827. ,lsOutside ///< Tick labels will be displayed outside the axis rect
  1828. };
  1829. Q_ENUMS(LabelSide)
  1830. /*!
  1831. Defines the scale of an axis.
  1832. \see setScaleType
  1833. */
  1834. enum ScaleType { stLinear ///< Linear scaling
  1835. ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed axis coordinates (possibly also \ref setTicker to a \ref QCPAxisTickerLog instance).
  1836. };
  1837. Q_ENUMS(ScaleType)
  1838. /*!
  1839. Defines the selectable parts of an axis.
  1840. \see setSelectableParts, setSelectedParts
  1841. */
  1842. enum SelectablePart { spNone = 0 ///< None of the selectable parts
  1843. ,spAxis = 0x001 ///< The axis backbone and tick marks
  1844. ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually)
  1845. ,spAxisLabel = 0x004 ///< The axis label
  1846. };
  1847. Q_ENUMS(SelectablePart)
  1848. Q_FLAGS(SelectableParts)
  1849. Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
  1850. explicit QCPAxis(QCPAxisRect *parent, AxisType type);
  1851. virtual ~QCPAxis() Q_DECL_OVERRIDE;
  1852. // getters:
  1853. AxisType axisType() const { return mAxisType; }
  1854. QCPAxisRect *axisRect() const { return mAxisRect; }
  1855. ScaleType scaleType() const { return mScaleType; }
  1856. const QCPRange range() const { return mRange; }
  1857. bool rangeReversed() const { return mRangeReversed; }
  1858. QSharedPointer<QCPAxisTicker> ticker() const { return mTicker; }
  1859. bool ticks() const { return mTicks; }
  1860. bool tickLabels() const { return mTickLabels; }
  1861. int tickLabelPadding() const;
  1862. QFont tickLabelFont() const { return mTickLabelFont; }
  1863. QColor tickLabelColor() const { return mTickLabelColor; }
  1864. double tickLabelRotation() const;
  1865. LabelSide tickLabelSide() const;
  1866. QString numberFormat() const;
  1867. int numberPrecision() const { return mNumberPrecision; }
  1868. QVector<double> tickVector() const { return mTickVector; }
  1869. QVector<QString> tickVectorLabels() const { return mTickVectorLabels; }
  1870. int tickLengthIn() const;
  1871. int tickLengthOut() const;
  1872. bool subTicks() const { return mSubTicks; }
  1873. int subTickLengthIn() const;
  1874. int subTickLengthOut() const;
  1875. QPen basePen() const { return mBasePen; }
  1876. QPen tickPen() const { return mTickPen; }
  1877. QPen subTickPen() const { return mSubTickPen; }
  1878. QFont labelFont() const { return mLabelFont; }
  1879. QColor labelColor() const { return mLabelColor; }
  1880. QString label() const { return mLabel; }
  1881. int labelPadding() const;
  1882. int padding() const { return mPadding; }
  1883. int offset() const;
  1884. SelectableParts selectedParts() const { return mSelectedParts; }
  1885. SelectableParts selectableParts() const { return mSelectableParts; }
  1886. QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; }
  1887. QFont selectedLabelFont() const { return mSelectedLabelFont; }
  1888. QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; }
  1889. QColor selectedLabelColor() const { return mSelectedLabelColor; }
  1890. QPen selectedBasePen() const { return mSelectedBasePen; }
  1891. QPen selectedTickPen() const { return mSelectedTickPen; }
  1892. QPen selectedSubTickPen() const { return mSelectedSubTickPen; }
  1893. QCPLineEnding lowerEnding() const;
  1894. QCPLineEnding upperEnding() const;
  1895. QCPGrid *grid() const { return mGrid; }
  1896. // setters:
  1897. Q_SLOT void setScaleType(QCPAxis::ScaleType type);
  1898. Q_SLOT void setRange(const QCPRange &range);
  1899. void setRange(double lower, double upper);
  1900. void setRange(double position, double size, Qt::AlignmentFlag alignment);
  1901. void setRangeLower(double lower);
  1902. void setRangeUpper(double upper);
  1903. void setRangeReversed(bool reversed);
  1904. void setTicker(QSharedPointer<QCPAxisTicker> ticker);
  1905. void setTicks(bool show);
  1906. void setTickLabels(bool show);
  1907. void setTickLabelPadding(int padding);
  1908. void setTickLabelFont(const QFont &font);
  1909. void setTickLabelColor(const QColor &color);
  1910. void setTickLabelRotation(double degrees);
  1911. void setTickLabelSide(LabelSide side);
  1912. void setNumberFormat(const QString &formatCode);
  1913. void setNumberPrecision(int precision);
  1914. void setTickLength(int inside, int outside=0);
  1915. void setTickLengthIn(int inside);
  1916. void setTickLengthOut(int outside);
  1917. void setSubTicks(bool show);
  1918. void setSubTickLength(int inside, int outside=0);
  1919. void setSubTickLengthIn(int inside);
  1920. void setSubTickLengthOut(int outside);
  1921. void setBasePen(const QPen &pen);
  1922. void setTickPen(const QPen &pen);
  1923. void setSubTickPen(const QPen &pen);
  1924. void setLabelFont(const QFont &font);
  1925. void setLabelColor(const QColor &color);
  1926. void setLabel(const QString &str);
  1927. void setLabelPadding(int padding);
  1928. void setPadding(int padding);
  1929. void setOffset(int offset);
  1930. void setSelectedTickLabelFont(const QFont &font);
  1931. void setSelectedLabelFont(const QFont &font);
  1932. void setSelectedTickLabelColor(const QColor &color);
  1933. void setSelectedLabelColor(const QColor &color);
  1934. void setSelectedBasePen(const QPen &pen);
  1935. void setSelectedTickPen(const QPen &pen);
  1936. void setSelectedSubTickPen(const QPen &pen);
  1937. Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts);
  1938. Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts);
  1939. void setLowerEnding(const QCPLineEnding &ending);
  1940. void setUpperEnding(const QCPLineEnding &ending);
  1941. // reimplemented virtual methods:
  1942. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  1943. // non-property methods:
  1944. Qt::Orientation orientation() const { return mOrientation; }
  1945. int pixelOrientation() const { return rangeReversed() != (orientation()==Qt::Vertical) ? -1 : 1; }
  1946. void moveRange(double diff);
  1947. void scaleRange(double factor);
  1948. void scaleRange(double factor, double center);
  1949. void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0);
  1950. void rescale(bool onlyVisiblePlottables=false);
  1951. double pixelToCoord(double value) const;
  1952. double coordToPixel(double value) const;
  1953. SelectablePart getPartAt(const QPointF &pos) const;
  1954. QList<QCPAbstractPlottable*> plottables() const;
  1955. QList<QCPGraph*> graphs() const;
  1956. QList<QCPAbstractItem*> items() const;
  1957. static AxisType marginSideToAxisType(QCP::MarginSide side);
  1958. static Qt::Orientation orientation(AxisType type) { return type==atBottom || type==atTop ? Qt::Horizontal : Qt::Vertical; }
  1959. static AxisType opposite(AxisType type);
  1960. signals:
  1961. void rangeChanged(const QCPRange &newRange);
  1962. void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange);
  1963. void scaleTypeChanged(QCPAxis::ScaleType scaleType);
  1964. void selectionChanged(const QCPAxis::SelectableParts &parts);
  1965. void selectableChanged(const QCPAxis::SelectableParts &parts);
  1966. protected:
  1967. // property members:
  1968. // axis base:
  1969. AxisType mAxisType;
  1970. QCPAxisRect *mAxisRect;
  1971. //int mOffset; // in QCPAxisPainter
  1972. int mPadding;
  1973. Qt::Orientation mOrientation;
  1974. SelectableParts mSelectableParts, mSelectedParts;
  1975. QPen mBasePen, mSelectedBasePen;
  1976. //QCPLineEnding mLowerEnding, mUpperEnding; // in QCPAxisPainter
  1977. // axis label:
  1978. //int mLabelPadding; // in QCPAxisPainter
  1979. QString mLabel;
  1980. QFont mLabelFont, mSelectedLabelFont;
  1981. QColor mLabelColor, mSelectedLabelColor;
  1982. // tick labels:
  1983. //int mTickLabelPadding; // in QCPAxisPainter
  1984. bool mTickLabels;
  1985. //double mTickLabelRotation; // in QCPAxisPainter
  1986. QFont mTickLabelFont, mSelectedTickLabelFont;
  1987. QColor mTickLabelColor, mSelectedTickLabelColor;
  1988. int mNumberPrecision;
  1989. QLatin1Char mNumberFormatChar;
  1990. bool mNumberBeautifulPowers;
  1991. //bool mNumberMultiplyCross; // QCPAxisPainter
  1992. // ticks and subticks:
  1993. bool mTicks;
  1994. bool mSubTicks;
  1995. //int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut; // QCPAxisPainter
  1996. QPen mTickPen, mSelectedTickPen;
  1997. QPen mSubTickPen, mSelectedSubTickPen;
  1998. // scale and range:
  1999. QCPRange mRange;
  2000. bool mRangeReversed;
  2001. ScaleType mScaleType;
  2002. // non-property members:
  2003. QCPGrid *mGrid;
  2004. QCPAxisPainterPrivate *mAxisPainter;
  2005. QSharedPointer<QCPAxisTicker> mTicker;
  2006. QVector<double> mTickVector;
  2007. QVector<QString> mTickVectorLabels;
  2008. QVector<double> mSubTickVector;
  2009. bool mCachedMarginValid;
  2010. int mCachedMargin;
  2011. bool mDragging;
  2012. QCPRange mDragStartRange;
  2013. QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
  2014. // introduced virtual methods:
  2015. virtual int calculateMargin();
  2016. // reimplemented virtual methods:
  2017. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  2018. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  2019. virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE;
  2020. // events:
  2021. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE;
  2022. virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE;
  2023. // mouse events:
  2024. virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE;
  2025. virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE;
  2026. virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE;
  2027. virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
  2028. // non-virtual methods:
  2029. void setupTickVectors();
  2030. QPen getBasePen() const;
  2031. QPen getTickPen() const;
  2032. QPen getSubTickPen() const;
  2033. QFont getTickLabelFont() const;
  2034. QFont getLabelFont() const;
  2035. QColor getTickLabelColor() const;
  2036. QColor getLabelColor() const;
  2037. private:
  2038. Q_DISABLE_COPY(QCPAxis)
  2039. friend class QCustomPlot;
  2040. friend class QCPGrid;
  2041. friend class QCPAxisRect;
  2042. };
  2043. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts)
  2044. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes)
  2045. Q_DECLARE_METATYPE(QCPAxis::AxisType)
  2046. Q_DECLARE_METATYPE(QCPAxis::LabelSide)
  2047. Q_DECLARE_METATYPE(QCPAxis::ScaleType)
  2048. Q_DECLARE_METATYPE(QCPAxis::SelectablePart)
  2049. class QCPAxisPainterPrivate
  2050. {
  2051. public:
  2052. explicit QCPAxisPainterPrivate(QCustomPlot *parentPlot);
  2053. virtual ~QCPAxisPainterPrivate();
  2054. virtual void draw(QCPPainter *painter);
  2055. virtual int size();
  2056. void clearCache();
  2057. QRect axisSelectionBox() const { return mAxisSelectionBox; }
  2058. QRect tickLabelsSelectionBox() const { return mTickLabelsSelectionBox; }
  2059. QRect labelSelectionBox() const { return mLabelSelectionBox; }
  2060. // public property members:
  2061. QCPAxis::AxisType type;
  2062. QPen basePen;
  2063. QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters
  2064. int labelPadding; // directly accessed by QCPAxis setters/getters
  2065. QFont labelFont;
  2066. QColor labelColor;
  2067. QString label;
  2068. int tickLabelPadding; // directly accessed by QCPAxis setters/getters
  2069. double tickLabelRotation; // directly accessed by QCPAxis setters/getters
  2070. QCPAxis::LabelSide tickLabelSide; // directly accessed by QCPAxis setters/getters
  2071. bool substituteExponent;
  2072. bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters
  2073. int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters
  2074. QPen tickPen, subTickPen;
  2075. QFont tickLabelFont;
  2076. QColor tickLabelColor;
  2077. QRect axisRect, viewportRect;
  2078. int offset; // directly accessed by QCPAxis setters/getters
  2079. bool abbreviateDecimalPowers;
  2080. bool reversedEndings;
  2081. QVector<double> subTickPositions;
  2082. QVector<double> tickPositions;
  2083. QVector<QString> tickLabels;
  2084. protected:
  2085. struct CachedLabel
  2086. {
  2087. QPointF offset;
  2088. QPixmap pixmap;
  2089. };
  2090. struct TickLabelData
  2091. {
  2092. QString basePart, expPart, suffixPart;
  2093. QRect baseBounds, expBounds, suffixBounds, totalBounds, rotatedTotalBounds;
  2094. QFont baseFont, expFont;
  2095. };
  2096. QCustomPlot *mParentPlot;
  2097. QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters
  2098. QCache<QString, CachedLabel> mLabelCache;
  2099. QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox;
  2100. virtual QByteArray generateLabelParameterHash() const;
  2101. virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize);
  2102. virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const;
  2103. virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const;
  2104. virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const;
  2105. virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const;
  2106. };
  2107. /* end of 'src/axis/axis.h' */
  2108. /* including file 'src/scatterstyle.h' */
  2109. /* modified 2022-11-06T12:45:56, size 7275 */
  2110. class QCP_LIB_DECL QCPScatterStyle
  2111. {
  2112. Q_GADGET
  2113. public:
  2114. /*!
  2115. Represents the various properties of a scatter style instance. For example, this enum is used
  2116. to specify which properties of \ref QCPSelectionDecorator::setScatterStyle will be used when
  2117. highlighting selected data points.
  2118. Specific scatter properties can be transferred between \ref QCPScatterStyle instances via \ref
  2119. setFromOther.
  2120. */
  2121. enum ScatterProperty { spNone = 0x00 ///< <tt>0x00</tt> None
  2122. ,spPen = 0x01 ///< <tt>0x01</tt> The pen property, see \ref setPen
  2123. ,spBrush = 0x02 ///< <tt>0x02</tt> The brush property, see \ref setBrush
  2124. ,spSize = 0x04 ///< <tt>0x04</tt> The size property, see \ref setSize
  2125. ,spShape = 0x08 ///< <tt>0x08</tt> The shape property, see \ref setShape
  2126. ,spAll = 0xFF ///< <tt>0xFF</tt> All properties
  2127. };
  2128. Q_ENUMS(ScatterProperty)
  2129. Q_FLAGS(ScatterProperties)
  2130. Q_DECLARE_FLAGS(ScatterProperties, ScatterProperty)
  2131. /*!
  2132. Defines the shape used for scatter points.
  2133. On plottables/items that draw scatters, the sizes of these visualizations (with exception of
  2134. \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are
  2135. drawn with the pen and brush specified with \ref setPen and \ref setBrush.
  2136. */
  2137. enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines)
  2138. ,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius)
  2139. ,ssCross ///< \enumimage{ssCross.png} a cross
  2140. ,ssPlus ///< \enumimage{ssPlus.png} a plus
  2141. ,ssCircle ///< \enumimage{ssCircle.png} a circle
  2142. ,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle)
  2143. ,ssSquare ///< \enumimage{ssSquare.png} a square
  2144. ,ssDiamond ///< \enumimage{ssDiamond.png} a diamond
  2145. ,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus
  2146. ,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline
  2147. ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner
  2148. ,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside
  2149. ,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside
  2150. ,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside
  2151. ,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside
  2152. ,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines
  2153. ,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates
  2154. ,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath)
  2155. };
  2156. Q_ENUMS(ScatterShape)
  2157. QCPScatterStyle();
  2158. QCPScatterStyle(ScatterShape shape, double size=6);
  2159. QCPScatterStyle(ScatterShape shape, const QColor &color, double size);
  2160. QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size);
  2161. QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size);
  2162. QCPScatterStyle(const QPixmap &pixmap);
  2163. QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6);
  2164. // getters:
  2165. double size() const { return mSize; }
  2166. ScatterShape shape() const { return mShape; }
  2167. QPen pen() const { return mPen; }
  2168. QBrush brush() const { return mBrush; }
  2169. QPixmap pixmap() const { return mPixmap; }
  2170. QPainterPath customPath() const { return mCustomPath; }
  2171. // setters:
  2172. void setFromOther(const QCPScatterStyle &other, ScatterProperties properties);
  2173. void setSize(double size);
  2174. void setShape(ScatterShape shape);
  2175. void setPen(const QPen &pen);
  2176. void setBrush(const QBrush &brush);
  2177. void setPixmap(const QPixmap &pixmap);
  2178. void setCustomPath(const QPainterPath &customPath);
  2179. // non-property methods:
  2180. bool isNone() const { return mShape == ssNone; }
  2181. bool isPenDefined() const { return mPenDefined; }
  2182. void undefinePen();
  2183. void applyTo(QCPPainter *painter, const QPen &defaultPen) const;
  2184. void drawShape(QCPPainter *painter, const QPointF &pos) const;
  2185. void drawShape(QCPPainter *painter, double x, double y) const;
  2186. protected:
  2187. // property members:
  2188. double mSize;
  2189. ScatterShape mShape;
  2190. QPen mPen;
  2191. QBrush mBrush;
  2192. QPixmap mPixmap;
  2193. QPainterPath mCustomPath;
  2194. // non-property members:
  2195. bool mPenDefined;
  2196. };
  2197. Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE);
  2198. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPScatterStyle::ScatterProperties)
  2199. Q_DECLARE_METATYPE(QCPScatterStyle::ScatterProperty)
  2200. Q_DECLARE_METATYPE(QCPScatterStyle::ScatterShape)
  2201. /* end of 'src/scatterstyle.h' */
  2202. /* including file 'src/datacontainer.h' */
  2203. /* modified 2022-11-06T12:45:56, size 34305 */
  2204. /*! \relates QCPDataContainer
  2205. Returns whether the sort key of \a a is less than the sort key of \a b.
  2206. \see QCPDataContainer::sort
  2207. */
  2208. template <class DataType>
  2209. inline bool qcpLessThanSortKey(const DataType &a, const DataType &b) { return a.sortKey() < b.sortKey(); }
  2210. template <class DataType>
  2211. class QCPDataContainer // no QCP_LIB_DECL, template class ends up in header (cpp included below)
  2212. {
  2213. public:
  2214. typedef typename QVector<DataType>::const_iterator const_iterator;
  2215. typedef typename QVector<DataType>::iterator iterator;
  2216. QCPDataContainer();
  2217. // getters:
  2218. int size() const { return mData.size()-mPreallocSize; }
  2219. bool isEmpty() const { return size() == 0; }
  2220. bool autoSqueeze() const { return mAutoSqueeze; }
  2221. // setters:
  2222. void setAutoSqueeze(bool enabled);
  2223. // non-virtual methods:
  2224. void set(const QCPDataContainer<DataType> &data);
  2225. void set(const QVector<DataType> &data, bool alreadySorted=false);
  2226. void add(const QCPDataContainer<DataType> &data);
  2227. void add(const QVector<DataType> &data, bool alreadySorted=false);
  2228. void add(const DataType &data);
  2229. void removeBefore(double sortKey);
  2230. void removeAfter(double sortKey);
  2231. void remove(double sortKeyFrom, double sortKeyTo);
  2232. void remove(double sortKey);
  2233. void clear();
  2234. void sort();
  2235. void squeeze(bool preAllocation=true, bool postAllocation=true);
  2236. const_iterator constBegin() const { return mData.constBegin()+mPreallocSize; }
  2237. const_iterator constEnd() const { return mData.constEnd(); }
  2238. iterator begin() { return mData.begin()+mPreallocSize; }
  2239. iterator end() { return mData.end(); }
  2240. const_iterator findBegin(double sortKey, bool expandedRange=true) const;
  2241. const_iterator findEnd(double sortKey, bool expandedRange=true) const;
  2242. const_iterator at(int index) const { return constBegin()+qBound(0, index, size()); }
  2243. QCPRange keyRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth);
  2244. QCPRange valueRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange());
  2245. QCPDataRange dataRange() const { return QCPDataRange(0, size()); }
  2246. void limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const;
  2247. protected:
  2248. // property members:
  2249. bool mAutoSqueeze;
  2250. // non-property memebers:
  2251. QVector<DataType> mData;
  2252. int mPreallocSize;
  2253. int mPreallocIteration;
  2254. // non-virtual methods:
  2255. void preallocateGrow(int minimumPreallocSize);
  2256. void performAutoSqueeze();
  2257. };
  2258. // include implementation in header since it is a class template:
  2259. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2260. //////////////////// QCPDataContainer
  2261. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2262. /*! \class QCPDataContainer
  2263. \brief The generic data container for one-dimensional plottables
  2264. This class template provides a fast container for data storage of one-dimensional data. The data
  2265. type is specified as template parameter (called \a DataType in the following) and must provide
  2266. some methods as described in the \ref qcpdatacontainer-datatype "next section".
  2267. The data is stored in a sorted fashion, which allows very quick lookups by the sorted key as well
  2268. as retrieval of ranges (see \ref findBegin, \ref findEnd, \ref keyRange) using binary search. The
  2269. container uses a preallocation and a postallocation scheme, such that appending and prepending
  2270. data (with respect to the sort key) is very fast and minimizes reallocations. If data is added
  2271. which needs to be inserted between existing keys, the merge usually can be done quickly too,
  2272. using the fact that existing data is always sorted. The user can further improve performance by
  2273. specifying that added data is already itself sorted by key, if he can guarantee that this is the
  2274. case (see for example \ref add(const QVector<DataType> &data, bool alreadySorted)).
  2275. The data can be accessed with the provided const iterators (\ref constBegin, \ref constEnd). If
  2276. it is necessary to alter existing data in-place, the non-const iterators can be used (\ref begin,
  2277. \ref end). Changing data members that are not the sort key (for most data types called \a key) is
  2278. safe from the container's perspective.
  2279. Great care must be taken however if the sort key is modified through the non-const iterators. For
  2280. performance reasons, the iterators don't automatically cause a re-sorting upon their
  2281. manipulation. It is thus the responsibility of the user to leave the container in a sorted state
  2282. when finished with the data manipulation, before calling any other methods on the container. A
  2283. complete re-sort (e.g. after finishing all sort key manipulation) can be done by calling \ref
  2284. sort. Failing to do so can not be detected by the container efficiently and will cause both
  2285. rendering artifacts and potential data loss.
  2286. Implementing one-dimensional plottables that make use of a \ref QCPDataContainer<T> is usually
  2287. done by subclassing from \ref QCPAbstractPlottable1D "QCPAbstractPlottable1D<T>", which
  2288. introduces an according \a mDataContainer member and some convenience methods.
  2289. \section qcpdatacontainer-datatype Requirements for the DataType template parameter
  2290. The template parameter <tt>DataType</tt> is the type of the stored data points. It must be
  2291. trivially copyable and have the following public methods, preferably inline:
  2292. \li <tt>double sortKey() const</tt>\n Returns the member variable of this data point that is the
  2293. sort key, defining the ordering in the container. Often this variable is simply called \a key.
  2294. \li <tt>static DataType fromSortKey(double sortKey)</tt>\n Returns a new instance of the data
  2295. type initialized with its sort key set to \a sortKey.
  2296. \li <tt>static bool sortKeyIsMainKey()</tt>\n Returns true if the sort key is equal to the main
  2297. key (see method \c mainKey below). For most plottables this is the case. It is not the case for
  2298. example for \ref QCPCurve, which uses \a t as sort key and \a key as main key. This is the reason
  2299. why QCPCurve unlike QCPGraph can display parametric curves with loops.
  2300. \li <tt>double mainKey() const</tt>\n Returns the variable of this data point considered the main
  2301. key. This is commonly the variable that is used as the coordinate of this data point on the key
  2302. axis of the plottable. This method is used for example when determining the automatic axis
  2303. rescaling of key axes (\ref QCPAxis::rescale).
  2304. \li <tt>double mainValue() const</tt>\n Returns the variable of this data point considered the
  2305. main value. This is commonly the variable that is used as the coordinate of this data point on
  2306. the value axis of the plottable.
  2307. \li <tt>QCPRange valueRange() const</tt>\n Returns the range this data point spans in the value
  2308. axis coordinate. If the data is single-valued (e.g. QCPGraphData), this is simply a range with
  2309. both lower and upper set to the main data point value. However if the data points can represent
  2310. multiple values at once (e.g QCPFinancialData with its \a high, \a low, \a open and \a close
  2311. values at each \a key) this method should return the range those values span. This method is used
  2312. for example when determining the automatic axis rescaling of value axes (\ref
  2313. QCPAxis::rescale).
  2314. */
  2315. /* start documentation of inline functions */
  2316. /*! \fn int QCPDataContainer<DataType>::size() const
  2317. Returns the number of data points in the container.
  2318. */
  2319. /*! \fn bool QCPDataContainer<DataType>::isEmpty() const
  2320. Returns whether this container holds no data points.
  2321. */
  2322. /*! \fn QCPDataContainer::const_iterator QCPDataContainer<DataType>::constBegin() const
  2323. Returns a const iterator to the first data point in this container.
  2324. */
  2325. /*! \fn QCPDataContainer::const_iterator QCPDataContainer<DataType>::constEnd() const
  2326. Returns a const iterator to the element past the last data point in this container.
  2327. */
  2328. /*! \fn QCPDataContainer::iterator QCPDataContainer<DataType>::begin() const
  2329. Returns a non-const iterator to the first data point in this container.
  2330. You can manipulate the data points in-place through the non-const iterators, but great care must
  2331. be taken when manipulating the sort key of a data point, see \ref sort, or the detailed
  2332. description of this class.
  2333. */
  2334. /*! \fn QCPDataContainer::iterator QCPDataContainer<DataType>::end() const
  2335. Returns a non-const iterator to the element past the last data point in this container.
  2336. You can manipulate the data points in-place through the non-const iterators, but great care must
  2337. be taken when manipulating the sort key of a data point, see \ref sort, or the detailed
  2338. description of this class.
  2339. */
  2340. /*! \fn QCPDataContainer::const_iterator QCPDataContainer<DataType>::at(int index) const
  2341. Returns a const iterator to the element with the specified \a index. If \a index points beyond
  2342. the available elements in this container, returns \ref constEnd, i.e. an iterator past the last
  2343. valid element.
  2344. You can use this method to easily obtain iterators from a \ref QCPDataRange, see the \ref
  2345. dataselection-accessing "data selection page" for an example.
  2346. */
  2347. /*! \fn QCPDataRange QCPDataContainer::dataRange() const
  2348. Returns a \ref QCPDataRange encompassing the entire data set of this container. This means the
  2349. begin index of the returned range is 0, and the end index is \ref size.
  2350. */
  2351. /* end documentation of inline functions */
  2352. /*!
  2353. Constructs a QCPDataContainer used for plottable classes that represent a series of key-sorted
  2354. data
  2355. */
  2356. template <class DataType>
  2357. QCPDataContainer<DataType>::QCPDataContainer() :
  2358. mAutoSqueeze(true),
  2359. mPreallocSize(0),
  2360. mPreallocIteration(0)
  2361. {
  2362. }
  2363. /*!
  2364. Sets whether the container automatically decides when to release memory from its post- and
  2365. preallocation pools when data points are removed. By default this is enabled and for typical
  2366. applications shouldn't be changed.
  2367. If auto squeeze is disabled, you can manually decide when to release pre-/postallocation with
  2368. \ref squeeze.
  2369. */
  2370. template <class DataType>
  2371. void QCPDataContainer<DataType>::setAutoSqueeze(bool enabled)
  2372. {
  2373. if (mAutoSqueeze != enabled)
  2374. {
  2375. mAutoSqueeze = enabled;
  2376. if (mAutoSqueeze)
  2377. performAutoSqueeze();
  2378. }
  2379. }
  2380. /*! \overload
  2381. Replaces the current data in this container with the provided \a data.
  2382. \see add, remove
  2383. */
  2384. template <class DataType>
  2385. void QCPDataContainer<DataType>::set(const QCPDataContainer<DataType> &data)
  2386. {
  2387. clear();
  2388. add(data);
  2389. }
  2390. /*! \overload
  2391. Replaces the current data in this container with the provided \a data
  2392. If you can guarantee that the data points in \a data have ascending order with respect to the
  2393. DataType's sort key, set \a alreadySorted to true to avoid an unnecessary sorting run.
  2394. \see add, remove
  2395. */
  2396. template <class DataType>
  2397. void QCPDataContainer<DataType>::set(const QVector<DataType> &data, bool alreadySorted)
  2398. {
  2399. mData = data;
  2400. mPreallocSize = 0;
  2401. mPreallocIteration = 0;
  2402. if (!alreadySorted)
  2403. sort();
  2404. }
  2405. /*! \overload
  2406. Adds the provided \a data to the current data in this container.
  2407. \see set, remove
  2408. */
  2409. template <class DataType>
  2410. void QCPDataContainer<DataType>::add(const QCPDataContainer<DataType> &data)
  2411. {
  2412. if (data.isEmpty())
  2413. return;
  2414. const int n = data.size();
  2415. const int oldSize = size();
  2416. if (oldSize > 0 && !qcpLessThanSortKey<DataType>(*constBegin(), *(data.constEnd()-1))) // prepend if new data keys are all smaller than or equal to existing ones
  2417. {
  2418. if (mPreallocSize < n)
  2419. preallocateGrow(n);
  2420. mPreallocSize -= n;
  2421. std::copy(data.constBegin(), data.constEnd(), begin());
  2422. } else // don't need to prepend, so append and merge if necessary
  2423. {
  2424. mData.resize(mData.size()+n);
  2425. std::copy(data.constBegin(), data.constEnd(), end()-n);
  2426. if (oldSize > 0 && !qcpLessThanSortKey<DataType>(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions
  2427. std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey<DataType>);
  2428. }
  2429. }
  2430. /*!
  2431. Adds the provided data points in \a data to the current data.
  2432. If you can guarantee that the data points in \a data have ascending order with respect to the
  2433. DataType's sort key, set \a alreadySorted to true to avoid an unnecessary sorting run.
  2434. \see set, remove
  2435. */
  2436. template <class DataType>
  2437. void QCPDataContainer<DataType>::add(const QVector<DataType> &data, bool alreadySorted)
  2438. {
  2439. if (data.isEmpty())
  2440. return;
  2441. if (isEmpty())
  2442. {
  2443. set(data, alreadySorted);
  2444. return;
  2445. }
  2446. const int n = data.size();
  2447. const int oldSize = size();
  2448. if (alreadySorted && oldSize > 0 && !qcpLessThanSortKey<DataType>(*constBegin(), *(data.constEnd()-1))) // prepend if new data is sorted and keys are all smaller than or equal to existing ones
  2449. {
  2450. if (mPreallocSize < n)
  2451. preallocateGrow(n);
  2452. mPreallocSize -= n;
  2453. std::copy(data.constBegin(), data.constEnd(), begin());
  2454. } else // don't need to prepend, so append and then sort and merge if necessary
  2455. {
  2456. mData.resize(mData.size()+n);
  2457. std::copy(data.constBegin(), data.constEnd(), end()-n);
  2458. if (!alreadySorted) // sort appended subrange if it wasn't already sorted
  2459. std::sort(end()-n, end(), qcpLessThanSortKey<DataType>);
  2460. if (oldSize > 0 && !qcpLessThanSortKey<DataType>(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions
  2461. std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey<DataType>);
  2462. }
  2463. }
  2464. /*! \overload
  2465. Adds the provided single data point to the current data.
  2466. \see remove
  2467. */
  2468. template <class DataType>
  2469. void QCPDataContainer<DataType>::add(const DataType &data)
  2470. {
  2471. if (isEmpty() || !qcpLessThanSortKey<DataType>(data, *(constEnd()-1))) // quickly handle appends if new data key is greater or equal to existing ones
  2472. {
  2473. mData.append(data);
  2474. } else if (qcpLessThanSortKey<DataType>(data, *constBegin())) // quickly handle prepends using preallocated space
  2475. {
  2476. if (mPreallocSize < 1)
  2477. preallocateGrow(1);
  2478. --mPreallocSize;
  2479. *begin() = data;
  2480. } else // handle inserts, maintaining sorted keys
  2481. {
  2482. QCPDataContainer<DataType>::iterator insertionPoint = std::lower_bound(begin(), end(), data, qcpLessThanSortKey<DataType>);
  2483. mData.insert(insertionPoint, data);
  2484. }
  2485. }
  2486. /*!
  2487. Removes all data points with (sort-)keys smaller than or equal to \a sortKey.
  2488. \see removeAfter, remove, clear
  2489. */
  2490. template <class DataType>
  2491. void QCPDataContainer<DataType>::removeBefore(double sortKey)
  2492. {
  2493. QCPDataContainer<DataType>::iterator it = begin();
  2494. QCPDataContainer<DataType>::iterator itEnd = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey<DataType>);
  2495. mPreallocSize += int(itEnd-it); // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it)
  2496. if (mAutoSqueeze)
  2497. performAutoSqueeze();
  2498. }
  2499. /*!
  2500. Removes all data points with (sort-)keys greater than or equal to \a sortKey.
  2501. \see removeBefore, remove, clear
  2502. */
  2503. template <class DataType>
  2504. void QCPDataContainer<DataType>::removeAfter(double sortKey)
  2505. {
  2506. QCPDataContainer<DataType>::iterator it = std::upper_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey<DataType>);
  2507. QCPDataContainer<DataType>::iterator itEnd = end();
  2508. mData.erase(it, itEnd); // typically adds it to the postallocated block
  2509. if (mAutoSqueeze)
  2510. performAutoSqueeze();
  2511. }
  2512. /*!
  2513. Removes all data points with (sort-)keys between \a sortKeyFrom and \a sortKeyTo. if \a
  2514. sortKeyFrom is greater or equal to \a sortKeyTo, the function does nothing. To remove a single
  2515. data point with known (sort-)key, use \ref remove(double sortKey).
  2516. \see removeBefore, removeAfter, clear
  2517. */
  2518. template <class DataType>
  2519. void QCPDataContainer<DataType>::remove(double sortKeyFrom, double sortKeyTo)
  2520. {
  2521. if (sortKeyFrom >= sortKeyTo || isEmpty())
  2522. return;
  2523. QCPDataContainer<DataType>::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKeyFrom), qcpLessThanSortKey<DataType>);
  2524. QCPDataContainer<DataType>::iterator itEnd = std::upper_bound(it, end(), DataType::fromSortKey(sortKeyTo), qcpLessThanSortKey<DataType>);
  2525. mData.erase(it, itEnd);
  2526. if (mAutoSqueeze)
  2527. performAutoSqueeze();
  2528. }
  2529. /*! \overload
  2530. Removes a single data point at \a sortKey. If the position is not known with absolute (binary)
  2531. precision, consider using \ref remove(double sortKeyFrom, double sortKeyTo) with a small
  2532. fuzziness interval around the suspected position, depeding on the precision with which the
  2533. (sort-)key is known.
  2534. \see removeBefore, removeAfter, clear
  2535. */
  2536. template <class DataType>
  2537. void QCPDataContainer<DataType>::remove(double sortKey)
  2538. {
  2539. QCPDataContainer::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey<DataType>);
  2540. if (it != end() && it->sortKey() == sortKey)
  2541. {
  2542. if (it == begin())
  2543. ++mPreallocSize; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it)
  2544. else
  2545. mData.erase(it);
  2546. }
  2547. if (mAutoSqueeze)
  2548. performAutoSqueeze();
  2549. }
  2550. /*!
  2551. Removes all data points.
  2552. \see remove, removeAfter, removeBefore
  2553. */
  2554. template <class DataType>
  2555. void QCPDataContainer<DataType>::clear()
  2556. {
  2557. mData.clear();
  2558. mPreallocIteration = 0;
  2559. mPreallocSize = 0;
  2560. }
  2561. /*!
  2562. Re-sorts all data points in the container by their sort key.
  2563. When setting, adding or removing points using the QCPDataContainer interface (\ref set, \ref add,
  2564. \ref remove, etc.), the container makes sure to always stay in a sorted state such that a full
  2565. resort is never necessary. However, if you choose to directly manipulate the sort key on data
  2566. points by accessing and modifying it through the non-const iterators (\ref begin, \ref end), it
  2567. is your responsibility to bring the container back into a sorted state before any other methods
  2568. are called on it. This can be achieved by calling this method immediately after finishing the
  2569. sort key manipulation.
  2570. */
  2571. template <class DataType>
  2572. void QCPDataContainer<DataType>::sort()
  2573. {
  2574. std::sort(begin(), end(), qcpLessThanSortKey<DataType>);
  2575. }
  2576. /*!
  2577. Frees all unused memory that is currently in the preallocation and postallocation pools.
  2578. Note that QCPDataContainer automatically decides whether squeezing is necessary, if \ref
  2579. setAutoSqueeze is left enabled. It should thus not be necessary to use this method for typical
  2580. applications.
  2581. The parameters \a preAllocation and \a postAllocation control whether pre- and/or post allocation
  2582. should be freed, respectively.
  2583. */
  2584. template <class DataType>
  2585. void QCPDataContainer<DataType>::squeeze(bool preAllocation, bool postAllocation)
  2586. {
  2587. if (preAllocation)
  2588. {
  2589. if (mPreallocSize > 0)
  2590. {
  2591. std::copy(begin(), end(), mData.begin());
  2592. mData.resize(size());
  2593. mPreallocSize = 0;
  2594. }
  2595. mPreallocIteration = 0;
  2596. }
  2597. if (postAllocation)
  2598. mData.squeeze();
  2599. }
  2600. /*!
  2601. Returns an iterator to the data point with a (sort-)key that is equal to, just below, or just
  2602. above \a sortKey. If \a expandedRange is true, the data point just below \a sortKey will be
  2603. considered, otherwise the one just above.
  2604. This can be used in conjunction with \ref findEnd to iterate over data points within a given key
  2605. range, including or excluding the bounding data points that are just beyond the specified range.
  2606. If \a expandedRange is true but there are no data points below \a sortKey, \ref constBegin is
  2607. returned.
  2608. If the container is empty, returns \ref constEnd.
  2609. \see findEnd, QCPPlottableInterface1D::findBegin
  2610. */
  2611. template <class DataType>
  2612. typename QCPDataContainer<DataType>::const_iterator QCPDataContainer<DataType>::findBegin(double sortKey, bool expandedRange) const
  2613. {
  2614. if (isEmpty())
  2615. return constEnd();
  2616. QCPDataContainer<DataType>::const_iterator it = std::lower_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey<DataType>);
  2617. if (expandedRange && it != constBegin()) // also covers it == constEnd case, and we know --constEnd is valid because mData isn't empty
  2618. --it;
  2619. return it;
  2620. }
  2621. /*!
  2622. Returns an iterator to the element after the data point with a (sort-)key that is equal to, just
  2623. above or just below \a sortKey. If \a expandedRange is true, the data point just above \a sortKey
  2624. will be considered, otherwise the one just below.
  2625. This can be used in conjunction with \ref findBegin to iterate over data points within a given
  2626. key range, including the bounding data points that are just below and above the specified range.
  2627. If \a expandedRange is true but there are no data points above \a sortKey, \ref constEnd is
  2628. returned.
  2629. If the container is empty, \ref constEnd is returned.
  2630. \see findBegin, QCPPlottableInterface1D::findEnd
  2631. */
  2632. template <class DataType>
  2633. typename QCPDataContainer<DataType>::const_iterator QCPDataContainer<DataType>::findEnd(double sortKey, bool expandedRange) const
  2634. {
  2635. if (isEmpty())
  2636. return constEnd();
  2637. QCPDataContainer<DataType>::const_iterator it = std::upper_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey<DataType>);
  2638. if (expandedRange && it != constEnd())
  2639. ++it;
  2640. return it;
  2641. }
  2642. /*!
  2643. Returns the range encompassed by the (main-)key coordinate of all data points. The output
  2644. parameter \a foundRange indicates whether a sensible range was found. If this is false, you
  2645. should not use the returned QCPRange (e.g. the data container is empty or all points have the
  2646. same key).
  2647. Use \a signDomain to control which sign of the key coordinates should be considered. This is
  2648. relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a
  2649. time.
  2650. If the DataType reports that its main key is equal to the sort key (\a sortKeyIsMainKey), as is
  2651. the case for most plottables, this method uses this fact and finds the range very quickly.
  2652. \see valueRange
  2653. */
  2654. template <class DataType>
  2655. QCPRange QCPDataContainer<DataType>::keyRange(bool &foundRange, QCP::SignDomain signDomain)
  2656. {
  2657. if (isEmpty())
  2658. {
  2659. foundRange = false;
  2660. return QCPRange();
  2661. }
  2662. QCPRange range;
  2663. bool haveLower = false;
  2664. bool haveUpper = false;
  2665. double current;
  2666. QCPDataContainer<DataType>::const_iterator it = constBegin();
  2667. QCPDataContainer<DataType>::const_iterator itEnd = constEnd();
  2668. if (signDomain == QCP::sdBoth) // range may be anywhere
  2669. {
  2670. if (DataType::sortKeyIsMainKey()) // if DataType is sorted by main key (e.g. QCPGraph, but not QCPCurve), use faster algorithm by finding just first and last key with non-NaN value
  2671. {
  2672. while (it != itEnd) // find first non-nan going up from left
  2673. {
  2674. if (!qIsNaN(it->mainValue()))
  2675. {
  2676. range.lower = it->mainKey();
  2677. haveLower = true;
  2678. break;
  2679. }
  2680. ++it;
  2681. }
  2682. it = itEnd;
  2683. while (it != constBegin()) // find first non-nan going down from right
  2684. {
  2685. --it;
  2686. if (!qIsNaN(it->mainValue()))
  2687. {
  2688. range.upper = it->mainKey();
  2689. haveUpper = true;
  2690. break;
  2691. }
  2692. }
  2693. } else // DataType is not sorted by main key, go through all data points and accordingly expand range
  2694. {
  2695. while (it != itEnd)
  2696. {
  2697. if (!qIsNaN(it->mainValue()))
  2698. {
  2699. current = it->mainKey();
  2700. if (current < range.lower || !haveLower)
  2701. {
  2702. range.lower = current;
  2703. haveLower = true;
  2704. }
  2705. if (current > range.upper || !haveUpper)
  2706. {
  2707. range.upper = current;
  2708. haveUpper = true;
  2709. }
  2710. }
  2711. ++it;
  2712. }
  2713. }
  2714. } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain
  2715. {
  2716. while (it != itEnd)
  2717. {
  2718. if (!qIsNaN(it->mainValue()))
  2719. {
  2720. current = it->mainKey();
  2721. if ((current < range.lower || !haveLower) && current < 0)
  2722. {
  2723. range.lower = current;
  2724. haveLower = true;
  2725. }
  2726. if ((current > range.upper || !haveUpper) && current < 0)
  2727. {
  2728. range.upper = current;
  2729. haveUpper = true;
  2730. }
  2731. }
  2732. ++it;
  2733. }
  2734. } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain
  2735. {
  2736. while (it != itEnd)
  2737. {
  2738. if (!qIsNaN(it->mainValue()))
  2739. {
  2740. current = it->mainKey();
  2741. if ((current < range.lower || !haveLower) && current > 0)
  2742. {
  2743. range.lower = current;
  2744. haveLower = true;
  2745. }
  2746. if ((current > range.upper || !haveUpper) && current > 0)
  2747. {
  2748. range.upper = current;
  2749. haveUpper = true;
  2750. }
  2751. }
  2752. ++it;
  2753. }
  2754. }
  2755. foundRange = haveLower && haveUpper;
  2756. return range;
  2757. }
  2758. /*!
  2759. Returns the range encompassed by the value coordinates of the data points in the specified key
  2760. range (\a inKeyRange), using the full \a DataType::valueRange reported by the data points. The
  2761. output parameter \a foundRange indicates whether a sensible range was found. If this is false,
  2762. you should not use the returned QCPRange (e.g. the data container is empty or all points have the
  2763. same value).
  2764. Inf and -Inf data values are ignored.
  2765. If \a inKeyRange has both lower and upper bound set to zero (is equal to <tt>QCPRange()</tt>),
  2766. all data points are considered, without any restriction on the keys.
  2767. Use \a signDomain to control which sign of the value coordinates should be considered. This is
  2768. relevant e.g. for logarithmic plots which can mathematically only display one sign domain at a
  2769. time.
  2770. \see keyRange
  2771. */
  2772. template <class DataType>
  2773. QCPRange QCPDataContainer<DataType>::valueRange(bool &foundRange, QCP::SignDomain signDomain, const QCPRange &inKeyRange)
  2774. {
  2775. if (isEmpty())
  2776. {
  2777. foundRange = false;
  2778. return QCPRange();
  2779. }
  2780. QCPRange range;
  2781. const bool restrictKeyRange = inKeyRange != QCPRange();
  2782. bool haveLower = false;
  2783. bool haveUpper = false;
  2784. QCPRange current;
  2785. QCPDataContainer<DataType>::const_iterator itBegin = constBegin();
  2786. QCPDataContainer<DataType>::const_iterator itEnd = constEnd();
  2787. if (DataType::sortKeyIsMainKey() && restrictKeyRange)
  2788. {
  2789. itBegin = findBegin(inKeyRange.lower, false);
  2790. itEnd = findEnd(inKeyRange.upper, false);
  2791. }
  2792. if (signDomain == QCP::sdBoth) // range may be anywhere
  2793. {
  2794. for (QCPDataContainer<DataType>::const_iterator it = itBegin; it != itEnd; ++it)
  2795. {
  2796. if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper))
  2797. continue;
  2798. current = it->valueRange();
  2799. if ((current.lower < range.lower || !haveLower) && !qIsNaN(current.lower) && std::isfinite(current.lower))
  2800. {
  2801. range.lower = current.lower;
  2802. haveLower = true;
  2803. }
  2804. if ((current.upper > range.upper || !haveUpper) && !qIsNaN(current.upper) && std::isfinite(current.upper))
  2805. {
  2806. range.upper = current.upper;
  2807. haveUpper = true;
  2808. }
  2809. }
  2810. } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain
  2811. {
  2812. for (QCPDataContainer<DataType>::const_iterator it = itBegin; it != itEnd; ++it)
  2813. {
  2814. if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper))
  2815. continue;
  2816. current = it->valueRange();
  2817. if ((current.lower < range.lower || !haveLower) && current.lower < 0 && !qIsNaN(current.lower) && std::isfinite(current.lower))
  2818. {
  2819. range.lower = current.lower;
  2820. haveLower = true;
  2821. }
  2822. if ((current.upper > range.upper || !haveUpper) && current.upper < 0 && !qIsNaN(current.upper) && std::isfinite(current.upper))
  2823. {
  2824. range.upper = current.upper;
  2825. haveUpper = true;
  2826. }
  2827. }
  2828. } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain
  2829. {
  2830. for (QCPDataContainer<DataType>::const_iterator it = itBegin; it != itEnd; ++it)
  2831. {
  2832. if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper))
  2833. continue;
  2834. current = it->valueRange();
  2835. if ((current.lower < range.lower || !haveLower) && current.lower > 0 && !qIsNaN(current.lower) && std::isfinite(current.lower))
  2836. {
  2837. range.lower = current.lower;
  2838. haveLower = true;
  2839. }
  2840. if ((current.upper > range.upper || !haveUpper) && current.upper > 0 && !qIsNaN(current.upper) && std::isfinite(current.upper))
  2841. {
  2842. range.upper = current.upper;
  2843. haveUpper = true;
  2844. }
  2845. }
  2846. }
  2847. foundRange = haveLower && haveUpper;
  2848. return range;
  2849. }
  2850. /*!
  2851. Makes sure \a begin and \a end mark a data range that is both within the bounds of this data
  2852. container's data, as well as within the specified \a dataRange. The initial range described by
  2853. the passed iterators \a begin and \a end is never expanded, only contracted if necessary.
  2854. This function doesn't require for \a dataRange to be within the bounds of this data container's
  2855. valid range.
  2856. */
  2857. template <class DataType>
  2858. void QCPDataContainer<DataType>::limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const
  2859. {
  2860. QCPDataRange iteratorRange(int(begin-constBegin()), int(end-constBegin()));
  2861. iteratorRange = iteratorRange.bounded(dataRange.bounded(this->dataRange()));
  2862. begin = constBegin()+iteratorRange.begin();
  2863. end = constBegin()+iteratorRange.end();
  2864. }
  2865. /*! \internal
  2866. Increases the preallocation pool to have a size of at least \a minimumPreallocSize. Depending on
  2867. the preallocation history, the container will grow by more than requested, to speed up future
  2868. consecutive size increases.
  2869. if \a minimumPreallocSize is smaller than or equal to the current preallocation pool size, this
  2870. method does nothing.
  2871. */
  2872. template <class DataType>
  2873. void QCPDataContainer<DataType>::preallocateGrow(int minimumPreallocSize)
  2874. {
  2875. if (minimumPreallocSize <= mPreallocSize)
  2876. return;
  2877. int newPreallocSize = minimumPreallocSize;
  2878. newPreallocSize += (1u<<qBound(4, mPreallocIteration+4, 15)) - 12; // do 4 up to 32768-12 preallocation, doubling in each intermediate iteration
  2879. ++mPreallocIteration;
  2880. int sizeDifference = newPreallocSize-mPreallocSize;
  2881. mData.resize(mData.size()+sizeDifference);
  2882. std::copy_backward(mData.begin()+mPreallocSize, mData.end()-sizeDifference, mData.end());
  2883. mPreallocSize = newPreallocSize;
  2884. }
  2885. /*! \internal
  2886. This method decides, depending on the total allocation size and the size of the unused pre- and
  2887. postallocation pools, whether it is sensible to reduce the pools in order to free up unused
  2888. memory. It then possibly calls \ref squeeze to do the deallocation.
  2889. If \ref setAutoSqueeze is enabled, this method is called automatically each time data points are
  2890. removed from the container (e.g. \ref remove).
  2891. \note when changing the decision parameters, care must be taken not to cause a back-and-forth
  2892. between squeezing and reallocation due to the growth strategy of the internal QVector and \ref
  2893. preallocateGrow. The hysteresis between allocation and deallocation should be made high enough
  2894. (at the expense of possibly larger unused memory from time to time).
  2895. */
  2896. template <class DataType>
  2897. void QCPDataContainer<DataType>::performAutoSqueeze()
  2898. {
  2899. const int totalAlloc = mData.capacity();
  2900. const int postAllocSize = totalAlloc-mData.size();
  2901. const int usedSize = size();
  2902. bool shrinkPostAllocation = false;
  2903. bool shrinkPreAllocation = false;
  2904. if (totalAlloc > 650000) // if allocation is larger, shrink earlier with respect to total used size
  2905. {
  2906. shrinkPostAllocation = postAllocSize > usedSize*1.5; // QVector grow strategy is 2^n for static data. Watch out not to oscillate!
  2907. shrinkPreAllocation = mPreallocSize*10 > usedSize;
  2908. } else if (totalAlloc > 1000) // below 10 MiB raw data be generous with preallocated memory, below 1k points don't even bother
  2909. {
  2910. shrinkPostAllocation = postAllocSize > usedSize*5;
  2911. shrinkPreAllocation = mPreallocSize > usedSize*1.5; // preallocation can grow into postallocation, so can be smaller
  2912. }
  2913. if (shrinkPreAllocation || shrinkPostAllocation)
  2914. squeeze(shrinkPreAllocation, shrinkPostAllocation);
  2915. }
  2916. /* end of 'src/datacontainer.h' */
  2917. /* including file 'src/plottable.h' */
  2918. /* modified 2022-11-06T12:45:56, size 8461 */
  2919. class QCP_LIB_DECL QCPSelectionDecorator
  2920. {
  2921. Q_GADGET
  2922. public:
  2923. QCPSelectionDecorator();
  2924. virtual ~QCPSelectionDecorator();
  2925. // getters:
  2926. QPen pen() const { return mPen; }
  2927. QBrush brush() const { return mBrush; }
  2928. QCPScatterStyle scatterStyle() const { return mScatterStyle; }
  2929. QCPScatterStyle::ScatterProperties usedScatterProperties() const { return mUsedScatterProperties; }
  2930. // setters:
  2931. void setPen(const QPen &pen);
  2932. void setBrush(const QBrush &brush);
  2933. void setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties=QCPScatterStyle::spPen);
  2934. void setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties);
  2935. // non-virtual methods:
  2936. void applyPen(QCPPainter *painter) const;
  2937. void applyBrush(QCPPainter *painter) const;
  2938. QCPScatterStyle getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const;
  2939. // introduced virtual methods:
  2940. virtual void copyFrom(const QCPSelectionDecorator *other);
  2941. virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection);
  2942. protected:
  2943. // property members:
  2944. QPen mPen;
  2945. QBrush mBrush;
  2946. QCPScatterStyle mScatterStyle;
  2947. QCPScatterStyle::ScatterProperties mUsedScatterProperties;
  2948. // non-property members:
  2949. QCPAbstractPlottable *mPlottable;
  2950. // introduced virtual methods:
  2951. virtual bool registerWithPlottable(QCPAbstractPlottable *plottable);
  2952. private:
  2953. Q_DISABLE_COPY(QCPSelectionDecorator)
  2954. friend class QCPAbstractPlottable;
  2955. };
  2956. Q_DECLARE_METATYPE(QCPSelectionDecorator*)
  2957. class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable
  2958. {
  2959. Q_OBJECT
  2960. /// \cond INCLUDE_QPROPERTIES
  2961. Q_PROPERTY(QString name READ name WRITE setName)
  2962. Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill)
  2963. Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters)
  2964. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  2965. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  2966. Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis)
  2967. Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis)
  2968. Q_PROPERTY(QCP::SelectionType selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
  2969. Q_PROPERTY(QCPDataSelection selection READ selection WRITE setSelection NOTIFY selectionChanged)
  2970. Q_PROPERTY(QCPSelectionDecorator* selectionDecorator READ selectionDecorator WRITE setSelectionDecorator)
  2971. /// \endcond
  2972. public:
  2973. QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis);
  2974. virtual ~QCPAbstractPlottable() Q_DECL_OVERRIDE;
  2975. // getters:
  2976. QString name() const { return mName; }
  2977. bool antialiasedFill() const { return mAntialiasedFill; }
  2978. bool antialiasedScatters() const { return mAntialiasedScatters; }
  2979. QPen pen() const { return mPen; }
  2980. QBrush brush() const { return mBrush; }
  2981. QCPAxis *keyAxis() const { return mKeyAxis.data(); }
  2982. QCPAxis *valueAxis() const { return mValueAxis.data(); }
  2983. QCP::SelectionType selectable() const { return mSelectable; }
  2984. bool selected() const { return !mSelection.isEmpty(); }
  2985. QCPDataSelection selection() const { return mSelection; }
  2986. QCPSelectionDecorator *selectionDecorator() const { return mSelectionDecorator; }
  2987. // setters:
  2988. void setName(const QString &name);
  2989. void setAntialiasedFill(bool enabled);
  2990. void setAntialiasedScatters(bool enabled);
  2991. void setPen(const QPen &pen);
  2992. void setBrush(const QBrush &brush);
  2993. void setKeyAxis(QCPAxis *axis);
  2994. void setValueAxis(QCPAxis *axis);
  2995. Q_SLOT void setSelectable(QCP::SelectionType selectable);
  2996. Q_SLOT void setSelection(QCPDataSelection selection);
  2997. void setSelectionDecorator(QCPSelectionDecorator *decorator);
  2998. // introduced virtual methods:
  2999. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE = 0; // actually introduced in QCPLayerable as non-pure, but we want to force reimplementation for plottables
  3000. virtual QCPPlottableInterface1D *interface1D() { return nullptr; }
  3001. virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const = 0;
  3002. virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const = 0;
  3003. // non-property methods:
  3004. void coordsToPixels(double key, double value, double &x, double &y) const;
  3005. const QPointF coordsToPixels(double key, double value) const;
  3006. void pixelsToCoords(double x, double y, double &key, double &value) const;
  3007. void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const;
  3008. void rescaleAxes(bool onlyEnlarge=false) const;
  3009. void rescaleKeyAxis(bool onlyEnlarge=false) const;
  3010. void rescaleValueAxis(bool onlyEnlarge=false, bool inKeyRange=false) const;
  3011. bool addToLegend(QCPLegend *legend);
  3012. bool addToLegend();
  3013. bool removeFromLegend(QCPLegend *legend) const;
  3014. bool removeFromLegend() const;
  3015. signals:
  3016. void selectionChanged(bool selected);
  3017. void selectionChanged(const QCPDataSelection &selection);
  3018. void selectableChanged(QCP::SelectionType selectable);
  3019. protected:
  3020. // property members:
  3021. QString mName;
  3022. bool mAntialiasedFill, mAntialiasedScatters;
  3023. QPen mPen;
  3024. QBrush mBrush;
  3025. QPointer<QCPAxis> mKeyAxis, mValueAxis;
  3026. QCP::SelectionType mSelectable;
  3027. QCPDataSelection mSelection;
  3028. QCPSelectionDecorator *mSelectionDecorator;
  3029. // reimplemented virtual methods:
  3030. virtual QRect clipRect() const Q_DECL_OVERRIDE;
  3031. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0;
  3032. virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE;
  3033. void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  3034. // events:
  3035. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE;
  3036. virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE;
  3037. // introduced virtual methods:
  3038. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0;
  3039. // non-virtual methods:
  3040. void applyFillAntialiasingHint(QCPPainter *painter) const;
  3041. void applyScattersAntialiasingHint(QCPPainter *painter) const;
  3042. private:
  3043. Q_DISABLE_COPY(QCPAbstractPlottable)
  3044. friend class QCustomPlot;
  3045. friend class QCPAxis;
  3046. friend class QCPPlottableLegendItem;
  3047. };
  3048. /* end of 'src/plottable.h' */
  3049. /* including file 'src/item.h' */
  3050. /* modified 2022-11-06T12:45:56, size 9425 */
  3051. class QCP_LIB_DECL QCPItemAnchor
  3052. {
  3053. Q_GADGET
  3054. public:
  3055. QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId=-1);
  3056. virtual ~QCPItemAnchor();
  3057. // getters:
  3058. QString name() const { return mName; }
  3059. virtual QPointF pixelPosition() const;
  3060. protected:
  3061. // property members:
  3062. QString mName;
  3063. // non-property members:
  3064. QCustomPlot *mParentPlot;
  3065. QCPAbstractItem *mParentItem;
  3066. int mAnchorId;
  3067. QSet<QCPItemPosition*> mChildrenX, mChildrenY;
  3068. // introduced virtual methods:
  3069. virtual QCPItemPosition *toQCPItemPosition() { return nullptr; }
  3070. // non-virtual methods:
  3071. void addChildX(QCPItemPosition* pos); // called from pos when this anchor is set as parent
  3072. void removeChildX(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted
  3073. void addChildY(QCPItemPosition* pos); // called from pos when this anchor is set as parent
  3074. void removeChildY(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted
  3075. private:
  3076. Q_DISABLE_COPY(QCPItemAnchor)
  3077. friend class QCPItemPosition;
  3078. };
  3079. class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor
  3080. {
  3081. Q_GADGET
  3082. public:
  3083. /*!
  3084. Defines the ways an item position can be specified. Thus it defines what the numbers passed to
  3085. \ref setCoords actually mean.
  3086. \see setType
  3087. */
  3088. enum PositionType { ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget.
  3089. ,ptViewportRatio ///< Static positioning given by a fraction of the viewport size. For example, if you call setCoords(0, 0), the position will be at the top
  3090. ///< left corner of the viewport/widget. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and
  3091. ///< vertically at the top of the viewport/widget, etc.
  3092. ,ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect). For example, if you call setCoords(0, 0), the position will be at the top
  3093. ///< left corner of the axis rect. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and
  3094. ///< vertically at the top of the axis rect, etc. You can also go beyond the axis rect by providing negative coordinates or coordinates larger than 1.
  3095. ,ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes).
  3096. };
  3097. Q_ENUMS(PositionType)
  3098. QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name);
  3099. virtual ~QCPItemPosition() Q_DECL_OVERRIDE;
  3100. // getters:
  3101. PositionType type() const { return typeX(); }
  3102. PositionType typeX() const { return mPositionTypeX; }
  3103. PositionType typeY() const { return mPositionTypeY; }
  3104. QCPItemAnchor *parentAnchor() const { return parentAnchorX(); }
  3105. QCPItemAnchor *parentAnchorX() const { return mParentAnchorX; }
  3106. QCPItemAnchor *parentAnchorY() const { return mParentAnchorY; }
  3107. double key() const { return mKey; }
  3108. double value() const { return mValue; }
  3109. QPointF coords() const { return QPointF(mKey, mValue); }
  3110. QCPAxis *keyAxis() const { return mKeyAxis.data(); }
  3111. QCPAxis *valueAxis() const { return mValueAxis.data(); }
  3112. QCPAxisRect *axisRect() const;
  3113. virtual QPointF pixelPosition() const Q_DECL_OVERRIDE;
  3114. // setters:
  3115. void setType(PositionType type);
  3116. void setTypeX(PositionType type);
  3117. void setTypeY(PositionType type);
  3118. bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
  3119. bool setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
  3120. bool setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
  3121. void setCoords(double key, double value);
  3122. void setCoords(const QPointF &pos);
  3123. void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis);
  3124. void setAxisRect(QCPAxisRect *axisRect);
  3125. void setPixelPosition(const QPointF &pixelPosition);
  3126. protected:
  3127. // property members:
  3128. PositionType mPositionTypeX, mPositionTypeY;
  3129. QPointer<QCPAxis> mKeyAxis, mValueAxis;
  3130. QPointer<QCPAxisRect> mAxisRect;
  3131. double mKey, mValue;
  3132. QCPItemAnchor *mParentAnchorX, *mParentAnchorY;
  3133. // reimplemented virtual methods:
  3134. virtual QCPItemPosition *toQCPItemPosition() Q_DECL_OVERRIDE { return this; }
  3135. private:
  3136. Q_DISABLE_COPY(QCPItemPosition)
  3137. };
  3138. Q_DECLARE_METATYPE(QCPItemPosition::PositionType)
  3139. class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable
  3140. {
  3141. Q_OBJECT
  3142. /// \cond INCLUDE_QPROPERTIES
  3143. Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect)
  3144. Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect)
  3145. Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
  3146. Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
  3147. /// \endcond
  3148. public:
  3149. explicit QCPAbstractItem(QCustomPlot *parentPlot);
  3150. virtual ~QCPAbstractItem() Q_DECL_OVERRIDE;
  3151. // getters:
  3152. bool clipToAxisRect() const { return mClipToAxisRect; }
  3153. QCPAxisRect *clipAxisRect() const;
  3154. bool selectable() const { return mSelectable; }
  3155. bool selected() const { return mSelected; }
  3156. // setters:
  3157. void setClipToAxisRect(bool clip);
  3158. void setClipAxisRect(QCPAxisRect *rect);
  3159. Q_SLOT void setSelectable(bool selectable);
  3160. Q_SLOT void setSelected(bool selected);
  3161. // reimplemented virtual methods:
  3162. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE = 0;
  3163. // non-virtual methods:
  3164. QList<QCPItemPosition*> positions() const { return mPositions; }
  3165. QList<QCPItemAnchor*> anchors() const { return mAnchors; }
  3166. QCPItemPosition *position(const QString &name) const;
  3167. QCPItemAnchor *anchor(const QString &name) const;
  3168. bool hasAnchor(const QString &name) const;
  3169. signals:
  3170. void selectionChanged(bool selected);
  3171. void selectableChanged(bool selectable);
  3172. protected:
  3173. // property members:
  3174. bool mClipToAxisRect;
  3175. QPointer<QCPAxisRect> mClipAxisRect;
  3176. QList<QCPItemPosition*> mPositions;
  3177. QList<QCPItemAnchor*> mAnchors;
  3178. bool mSelectable, mSelected;
  3179. // reimplemented virtual methods:
  3180. virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE;
  3181. virtual QRect clipRect() const Q_DECL_OVERRIDE;
  3182. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  3183. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0;
  3184. // events:
  3185. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE;
  3186. virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE;
  3187. // introduced virtual methods:
  3188. virtual QPointF anchorPixelPosition(int anchorId) const;
  3189. // non-virtual methods:
  3190. double rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const;
  3191. QCPItemPosition *createPosition(const QString &name);
  3192. QCPItemAnchor *createAnchor(const QString &name, int anchorId);
  3193. private:
  3194. Q_DISABLE_COPY(QCPAbstractItem)
  3195. friend class QCustomPlot;
  3196. friend class QCPItemAnchor;
  3197. };
  3198. /* end of 'src/item.h' */
  3199. /* including file 'src/core.h' */
  3200. /* modified 2022-11-06T12:45:56, size 19304 */
  3201. class QCP_LIB_DECL QCustomPlot : public QWidget
  3202. {
  3203. Q_OBJECT
  3204. /// \cond INCLUDE_QPROPERTIES
  3205. Q_PROPERTY(QRect viewport READ viewport WRITE setViewport)
  3206. Q_PROPERTY(QPixmap background READ background WRITE setBackground)
  3207. Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
  3208. Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
  3209. Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout)
  3210. Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend)
  3211. Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance)
  3212. Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag)
  3213. Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier)
  3214. Q_PROPERTY(bool openGl READ openGl WRITE setOpenGl)
  3215. /// \endcond
  3216. public:
  3217. /*!
  3218. Defines how a layer should be inserted relative to an other layer.
  3219. \see addLayer, moveLayer
  3220. */
  3221. enum LayerInsertMode { limBelow ///< Layer is inserted below other layer
  3222. ,limAbove ///< Layer is inserted above other layer
  3223. };
  3224. Q_ENUMS(LayerInsertMode)
  3225. /*!
  3226. Defines with what timing the QCustomPlot surface is refreshed after a replot.
  3227. \see replot
  3228. */
  3229. enum RefreshPriority { rpImmediateRefresh ///< Replots immediately and repaints the widget immediately by calling QWidget::repaint() after the replot
  3230. ,rpQueuedRefresh ///< Replots immediately, but queues the widget repaint, by calling QWidget::update() after the replot. This way multiple redundant widget repaints can be avoided.
  3231. ,rpRefreshHint ///< Whether to use immediate or queued refresh depends on whether the plotting hint \ref QCP::phImmediateRefresh is set, see \ref setPlottingHints.
  3232. ,rpQueuedReplot ///< Queues the entire replot for the next event loop iteration. This way multiple redundant replots can be avoided. The actual replot is then done with \ref rpRefreshHint priority.
  3233. };
  3234. Q_ENUMS(RefreshPriority)
  3235. explicit QCustomPlot(QWidget *parent = nullptr);
  3236. virtual ~QCustomPlot() Q_DECL_OVERRIDE;
  3237. // getters:
  3238. QRect viewport() const { return mViewport; }
  3239. double bufferDevicePixelRatio() const { return mBufferDevicePixelRatio; }
  3240. QPixmap background() const { return mBackgroundPixmap; }
  3241. bool backgroundScaled() const { return mBackgroundScaled; }
  3242. Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
  3243. QCPLayoutGrid *plotLayout() const { return mPlotLayout; }
  3244. QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; }
  3245. QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; }
  3246. bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; }
  3247. const QCP::Interactions interactions() const { return mInteractions; }
  3248. int selectionTolerance() const { return mSelectionTolerance; }
  3249. bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; }
  3250. QCP::PlottingHints plottingHints() const { return mPlottingHints; }
  3251. Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; }
  3252. QCP::SelectionRectMode selectionRectMode() const { return mSelectionRectMode; }
  3253. QCPSelectionRect *selectionRect() const { return mSelectionRect; }
  3254. bool openGl() const { return mOpenGl; }
  3255. // setters:
  3256. void setViewport(const QRect &rect);
  3257. void setBufferDevicePixelRatio(double ratio);
  3258. void setBackground(const QPixmap &pm);
  3259. void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
  3260. void setBackground(const QBrush &brush);
  3261. void setBackgroundScaled(bool scaled);
  3262. void setBackgroundScaledMode(Qt::AspectRatioMode mode);
  3263. void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements);
  3264. void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true);
  3265. void setNotAntialiasedElements(const QCP::AntialiasedElements &notAntialiasedElements);
  3266. void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true);
  3267. void setAutoAddPlottableToLegend(bool on);
  3268. void setInteractions(const QCP::Interactions &interactions);
  3269. void setInteraction(const QCP::Interaction &interaction, bool enabled=true);
  3270. void setSelectionTolerance(int pixels);
  3271. void setNoAntialiasingOnDrag(bool enabled);
  3272. void setPlottingHints(const QCP::PlottingHints &hints);
  3273. void setPlottingHint(QCP::PlottingHint hint, bool enabled=true);
  3274. void setMultiSelectModifier(Qt::KeyboardModifier modifier);
  3275. void setSelectionRectMode(QCP::SelectionRectMode mode);
  3276. void setSelectionRect(QCPSelectionRect *selectionRect);
  3277. void setOpenGl(bool enabled, int multisampling=16);
  3278. // non-property methods:
  3279. // plottable interface:
  3280. QCPAbstractPlottable *plottable(int index);
  3281. QCPAbstractPlottable *plottable();
  3282. bool removePlottable(QCPAbstractPlottable *plottable);
  3283. bool removePlottable(int index);
  3284. int clearPlottables();
  3285. int plottableCount() const;
  3286. QList<QCPAbstractPlottable*> selectedPlottables() const;
  3287. template<class PlottableType>
  3288. PlottableType *plottableAt(const QPointF &pos, bool onlySelectable=false, int *dataIndex=nullptr) const;
  3289. QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false, int *dataIndex=nullptr) const;
  3290. bool hasPlottable(QCPAbstractPlottable *plottable) const;
  3291. // specialized interface for QCPGraph:
  3292. QCPGraph *graph(int index) const;
  3293. QCPGraph *graph() const;
  3294. QCPGraph *addGraph(QCPAxis *keyAxis=nullptr, QCPAxis *valueAxis=nullptr);
  3295. bool removeGraph(QCPGraph *graph);
  3296. bool removeGraph(int index);
  3297. int clearGraphs();
  3298. int graphCount() const;
  3299. QList<QCPGraph*> selectedGraphs() const;
  3300. // item interface:
  3301. QCPAbstractItem *item(int index) const;
  3302. QCPAbstractItem *item() const;
  3303. bool removeItem(QCPAbstractItem *item);
  3304. bool removeItem(int index);
  3305. int clearItems();
  3306. int itemCount() const;
  3307. QList<QCPAbstractItem*> selectedItems() const;
  3308. template<class ItemType>
  3309. ItemType *itemAt(const QPointF &pos, bool onlySelectable=false) const;
  3310. QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const;
  3311. bool hasItem(QCPAbstractItem *item) const;
  3312. // layer interface:
  3313. QCPLayer *layer(const QString &name) const;
  3314. QCPLayer *layer(int index) const;
  3315. QCPLayer *currentLayer() const;
  3316. bool setCurrentLayer(const QString &name);
  3317. bool setCurrentLayer(QCPLayer *layer);
  3318. int layerCount() const;
  3319. bool addLayer(const QString &name, QCPLayer *otherLayer=nullptr, LayerInsertMode insertMode=limAbove);
  3320. bool removeLayer(QCPLayer *layer);
  3321. bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove);
  3322. // axis rect/layout interface:
  3323. int axisRectCount() const;
  3324. QCPAxisRect* axisRect(int index=0) const;
  3325. QList<QCPAxisRect*> axisRects() const;
  3326. QCPLayoutElement* layoutElementAt(const QPointF &pos) const;
  3327. QCPAxisRect* axisRectAt(const QPointF &pos) const;
  3328. Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false);
  3329. QList<QCPAxis*> selectedAxes() const;
  3330. QList<QCPLegend*> selectedLegends() const;
  3331. Q_SLOT void deselectAll();
  3332. bool savePdf(const QString &fileName, int width=0, int height=0, QCP::ExportPen exportPen=QCP::epAllowCosmetic, const QString &pdfCreator=QString(), const QString &pdfTitle=QString());
  3333. bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch);
  3334. bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch);
  3335. bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch);
  3336. bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch);
  3337. QPixmap toPixmap(int width=0, int height=0, double scale=1.0);
  3338. void toPainter(QCPPainter *painter, int width=0, int height=0);
  3339. Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint);
  3340. double replotTime(bool average=false) const;
  3341. QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2;
  3342. QCPLegend *legend;
  3343. signals:
  3344. void mouseDoubleClick(QMouseEvent *event);
  3345. void mousePress(QMouseEvent *event);
  3346. void mouseMove(QMouseEvent *event);
  3347. void mouseRelease(QMouseEvent *event);
  3348. void mouseWheel(QWheelEvent *event);
  3349. void plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event);
  3350. void plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event);
  3351. void itemClick(QCPAbstractItem *item, QMouseEvent *event);
  3352. void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event);
  3353. void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
  3354. void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
  3355. void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
  3356. void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
  3357. void selectionChangedByUser();
  3358. void beforeReplot();
  3359. void afterLayout();
  3360. void afterReplot();
  3361. protected:
  3362. // property members:
  3363. QRect mViewport;
  3364. double mBufferDevicePixelRatio;
  3365. QCPLayoutGrid *mPlotLayout;
  3366. bool mAutoAddPlottableToLegend;
  3367. QList<QCPAbstractPlottable*> mPlottables;
  3368. QList<QCPGraph*> mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph
  3369. QList<QCPAbstractItem*> mItems;
  3370. QList<QCPLayer*> mLayers;
  3371. QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements;
  3372. QCP::Interactions mInteractions;
  3373. int mSelectionTolerance;
  3374. bool mNoAntialiasingOnDrag;
  3375. QBrush mBackgroundBrush;
  3376. QPixmap mBackgroundPixmap;
  3377. QPixmap mScaledBackgroundPixmap;
  3378. bool mBackgroundScaled;
  3379. Qt::AspectRatioMode mBackgroundScaledMode;
  3380. QCPLayer *mCurrentLayer;
  3381. QCP::PlottingHints mPlottingHints;
  3382. Qt::KeyboardModifier mMultiSelectModifier;
  3383. QCP::SelectionRectMode mSelectionRectMode;
  3384. QCPSelectionRect *mSelectionRect;
  3385. bool mOpenGl;
  3386. // non-property members:
  3387. QList<QSharedPointer<QCPAbstractPaintBuffer> > mPaintBuffers;
  3388. QPoint mMousePressPos;
  3389. bool mMouseHasMoved;
  3390. QPointer<QCPLayerable> mMouseEventLayerable;
  3391. QPointer<QCPLayerable> mMouseSignalLayerable;
  3392. QVariant mMouseEventLayerableDetails;
  3393. QVariant mMouseSignalLayerableDetails;
  3394. bool mReplotting;
  3395. bool mReplotQueued;
  3396. double mReplotTime, mReplotTimeAverage;
  3397. int mOpenGlMultisamples;
  3398. QCP::AntialiasedElements mOpenGlAntialiasedElementsBackup;
  3399. bool mOpenGlCacheLabelsBackup;
  3400. #ifdef QCP_OPENGL_FBO
  3401. QSharedPointer<QOpenGLContext> mGlContext;
  3402. QSharedPointer<QSurface> mGlSurface;
  3403. QSharedPointer<QOpenGLPaintDevice> mGlPaintDevice;
  3404. #endif
  3405. // reimplemented virtual methods:
  3406. virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE;
  3407. virtual QSize sizeHint() const Q_DECL_OVERRIDE;
  3408. virtual void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
  3409. virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
  3410. virtual void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  3411. virtual void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  3412. virtual void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  3413. virtual void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  3414. virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
  3415. // introduced virtual methods:
  3416. virtual void draw(QCPPainter *painter);
  3417. virtual void updateLayout();
  3418. virtual void axisRemoved(QCPAxis *axis);
  3419. virtual void legendRemoved(QCPLegend *legend);
  3420. Q_SLOT virtual void processRectSelection(QRect rect, QMouseEvent *event);
  3421. Q_SLOT virtual void processRectZoom(QRect rect, QMouseEvent *event);
  3422. Q_SLOT virtual void processPointSelection(QMouseEvent *event);
  3423. // non-virtual methods:
  3424. bool registerPlottable(QCPAbstractPlottable *plottable);
  3425. bool registerGraph(QCPGraph *graph);
  3426. bool registerItem(QCPAbstractItem* item);
  3427. void updateLayerIndices() const;
  3428. QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=nullptr) const;
  3429. QList<QCPLayerable*> layerableListAt(const QPointF &pos, bool onlySelectable, QList<QVariant> *selectionDetails=nullptr) const;
  3430. void drawBackground(QCPPainter *painter);
  3431. void setupPaintBuffers();
  3432. QCPAbstractPaintBuffer *createPaintBuffer();
  3433. bool hasInvalidatedPaintBuffers();
  3434. bool setupOpenGl();
  3435. void freeOpenGl();
  3436. friend class QCPLegend;
  3437. friend class QCPAxis;
  3438. friend class QCPLayer;
  3439. friend class QCPAxisRect;
  3440. friend class QCPAbstractPlottable;
  3441. friend class QCPGraph;
  3442. friend class QCPAbstractItem;
  3443. };
  3444. Q_DECLARE_METATYPE(QCustomPlot::LayerInsertMode)
  3445. Q_DECLARE_METATYPE(QCustomPlot::RefreshPriority)
  3446. // implementation of template functions:
  3447. /*!
  3448. Returns the plottable at the pixel position \a pos. The plottable type (a QCPAbstractPlottable
  3449. subclass) that shall be taken into consideration can be specified via the template parameter.
  3450. Plottables that only consist of single lines (like graphs) have a tolerance band around them, see
  3451. \ref setSelectionTolerance. If multiple plottables come into consideration, the one closest to \a
  3452. pos is returned.
  3453. If \a onlySelectable is true, only plottables that are selectable
  3454. (QCPAbstractPlottable::setSelectable) are considered.
  3455. if \a dataIndex is non-null, it is set to the index of the plottable's data point that is closest
  3456. to \a pos.
  3457. If there is no plottable of the specified type at \a pos, returns \c nullptr.
  3458. \see itemAt, layoutElementAt
  3459. */
  3460. template<class PlottableType>
  3461. PlottableType *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable, int *dataIndex) const
  3462. {
  3463. PlottableType *resultPlottable = 0;
  3464. QVariant resultDetails;
  3465. double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value
  3466. foreach (QCPAbstractPlottable *plottable, mPlottables)
  3467. {
  3468. PlottableType *currentPlottable = qobject_cast<PlottableType*>(plottable);
  3469. if (!currentPlottable || (onlySelectable && !currentPlottable->selectable())) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractPlottable::selectable
  3470. continue;
  3471. if (currentPlottable->clipRect().contains(pos.toPoint())) // only consider clicks where the plottable is actually visible
  3472. {
  3473. QVariant details;
  3474. double currentDistance = currentPlottable->selectTest(pos, false, dataIndex ? &details : nullptr);
  3475. if (currentDistance >= 0 && currentDistance < resultDistance)
  3476. {
  3477. resultPlottable = currentPlottable;
  3478. resultDetails = details;
  3479. resultDistance = currentDistance;
  3480. }
  3481. }
  3482. }
  3483. if (resultPlottable && dataIndex)
  3484. {
  3485. QCPDataSelection sel = resultDetails.value<QCPDataSelection>();
  3486. if (!sel.isEmpty())
  3487. *dataIndex = sel.dataRange(0).begin();
  3488. }
  3489. return resultPlottable;
  3490. }
  3491. /*!
  3492. Returns the item at the pixel position \a pos. The item type (a QCPAbstractItem subclass) that shall be
  3493. taken into consideration can be specified via the template parameter. Items that only consist of single
  3494. lines (e.g. \ref QCPItemLine or \ref QCPItemCurve) have a tolerance band around them, see \ref
  3495. setSelectionTolerance. If multiple items come into consideration, the one closest to \a pos is returned.
  3496. If \a onlySelectable is true, only items that are selectable (QCPAbstractItem::setSelectable) are
  3497. considered.
  3498. If there is no item at \a pos, returns \c nullptr.
  3499. \see plottableAt, layoutElementAt
  3500. */
  3501. template<class ItemType>
  3502. ItemType *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const
  3503. {
  3504. ItemType *resultItem = 0;
  3505. double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value
  3506. foreach (QCPAbstractItem *item, mItems)
  3507. {
  3508. ItemType *currentItem = qobject_cast<ItemType*>(item);
  3509. if (!currentItem || (onlySelectable && !currentItem->selectable())) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable
  3510. continue;
  3511. if (!currentItem->clipToAxisRect() || currentItem->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it
  3512. {
  3513. double currentDistance = currentItem->selectTest(pos, false);
  3514. if (currentDistance >= 0 && currentDistance < resultDistance)
  3515. {
  3516. resultItem = currentItem;
  3517. resultDistance = currentDistance;
  3518. }
  3519. }
  3520. }
  3521. return resultItem;
  3522. }
  3523. /* end of 'src/core.h' */
  3524. /* including file 'src/plottable1d.h' */
  3525. /* modified 2022-11-06T12:45:56, size 25638 */
  3526. class QCPPlottableInterface1D
  3527. {
  3528. public:
  3529. virtual ~QCPPlottableInterface1D() = default;
  3530. // introduced pure virtual methods:
  3531. virtual int dataCount() const = 0;
  3532. virtual double dataMainKey(int index) const = 0;
  3533. virtual double dataSortKey(int index) const = 0;
  3534. virtual double dataMainValue(int index) const = 0;
  3535. virtual QCPRange dataValueRange(int index) const = 0;
  3536. virtual QPointF dataPixelPosition(int index) const = 0;
  3537. virtual bool sortKeyIsMainKey() const = 0;
  3538. virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const = 0;
  3539. virtual int findBegin(double sortKey, bool expandedRange=true) const = 0;
  3540. virtual int findEnd(double sortKey, bool expandedRange=true) const = 0;
  3541. };
  3542. template <class DataType>
  3543. class QCPAbstractPlottable1D : public QCPAbstractPlottable, public QCPPlottableInterface1D // no QCP_LIB_DECL, template class ends up in header (cpp included below)
  3544. {
  3545. // No Q_OBJECT macro due to template class
  3546. public:
  3547. QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis);
  3548. virtual ~QCPAbstractPlottable1D() Q_DECL_OVERRIDE;
  3549. // virtual methods of 1d plottable interface:
  3550. virtual int dataCount() const Q_DECL_OVERRIDE;
  3551. virtual double dataMainKey(int index) const Q_DECL_OVERRIDE;
  3552. virtual double dataSortKey(int index) const Q_DECL_OVERRIDE;
  3553. virtual double dataMainValue(int index) const Q_DECL_OVERRIDE;
  3554. virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE;
  3555. virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE;
  3556. virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE;
  3557. virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE;
  3558. virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE;
  3559. virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE;
  3560. // reimplemented virtual methods:
  3561. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  3562. virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; }
  3563. protected:
  3564. // property members:
  3565. QSharedPointer<QCPDataContainer<DataType> > mDataContainer;
  3566. // helpers for subclasses:
  3567. void getDataSegments(QList<QCPDataRange> &selectedSegments, QList<QCPDataRange> &unselectedSegments) const;
  3568. void drawPolyline(QCPPainter *painter, const QVector<QPointF> &lineData) const;
  3569. private:
  3570. Q_DISABLE_COPY(QCPAbstractPlottable1D)
  3571. };
  3572. // include implementation in header since it is a class template:
  3573. ////////////////////////////////////////////////////////////////////////////////////////////////////
  3574. //////////////////// QCPPlottableInterface1D
  3575. ////////////////////////////////////////////////////////////////////////////////////////////////////
  3576. /*! \class QCPPlottableInterface1D
  3577. \brief Defines an abstract interface for one-dimensional plottables
  3578. This class contains only pure virtual methods which define a common interface to the data
  3579. of one-dimensional plottables.
  3580. For example, it is implemented by the template class \ref QCPAbstractPlottable1D (the preferred
  3581. base class for one-dimensional plottables). So if you use that template class as base class of
  3582. your one-dimensional plottable, you won't have to care about implementing the 1d interface
  3583. yourself.
  3584. If your plottable doesn't derive from \ref QCPAbstractPlottable1D but still wants to provide a 1d
  3585. interface (e.g. like \ref QCPErrorBars does), you should inherit from both \ref
  3586. QCPAbstractPlottable and \ref QCPPlottableInterface1D and accordingly reimplement the pure
  3587. virtual methods of the 1d interface, matching your data container. Also, reimplement \ref
  3588. QCPAbstractPlottable::interface1D to return the \c this pointer.
  3589. If you have a \ref QCPAbstractPlottable pointer, you can check whether it implements this
  3590. interface by calling \ref QCPAbstractPlottable::interface1D and testing it for a non-zero return
  3591. value. If it indeed implements this interface, you may use it to access the plottable's data
  3592. without needing to know the exact type of the plottable or its data point type.
  3593. */
  3594. /* start documentation of pure virtual functions */
  3595. /*! \fn virtual int QCPPlottableInterface1D::dataCount() const = 0;
  3596. Returns the number of data points of the plottable.
  3597. */
  3598. /*! \fn virtual QCPDataSelection QCPPlottableInterface1D::selectTestRect(const QRectF &rect, bool onlySelectable) const = 0;
  3599. Returns a data selection containing all the data points of this plottable which are contained (or
  3600. hit by) \a rect. This is used mainly in the selection rect interaction for data selection (\ref
  3601. dataselection "data selection mechanism").
  3602. If \a onlySelectable is true, an empty QCPDataSelection is returned if this plottable is not
  3603. selectable (i.e. if \ref QCPAbstractPlottable::setSelectable is \ref QCP::stNone).
  3604. \note \a rect must be a normalized rect (positive or zero width and height). This is especially
  3605. important when using the rect of \ref QCPSelectionRect::accepted, which is not necessarily
  3606. normalized. Use <tt>QRect::normalized()</tt> when passing a rect which might not be normalized.
  3607. */
  3608. /*! \fn virtual double QCPPlottableInterface1D::dataMainKey(int index) const = 0
  3609. Returns the main key of the data point at the given \a index.
  3610. What the main key is, is defined by the plottable's data type. See the \ref
  3611. qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming
  3612. convention.
  3613. */
  3614. /*! \fn virtual double QCPPlottableInterface1D::dataSortKey(int index) const = 0
  3615. Returns the sort key of the data point at the given \a index.
  3616. What the sort key is, is defined by the plottable's data type. See the \ref
  3617. qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming
  3618. convention.
  3619. */
  3620. /*! \fn virtual double QCPPlottableInterface1D::dataMainValue(int index) const = 0
  3621. Returns the main value of the data point at the given \a index.
  3622. What the main value is, is defined by the plottable's data type. See the \ref
  3623. qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming
  3624. convention.
  3625. */
  3626. /*! \fn virtual QCPRange QCPPlottableInterface1D::dataValueRange(int index) const = 0
  3627. Returns the value range of the data point at the given \a index.
  3628. What the value range is, is defined by the plottable's data type. See the \ref
  3629. qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming
  3630. convention.
  3631. */
  3632. /*! \fn virtual QPointF QCPPlottableInterface1D::dataPixelPosition(int index) const = 0
  3633. Returns the pixel position on the widget surface at which the data point at the given \a index
  3634. appears.
  3635. Usually this corresponds to the point of \ref dataMainKey/\ref dataMainValue, in pixel
  3636. coordinates. However, depending on the plottable, this might be a different apparent position
  3637. than just a coord-to-pixel transform of those values. For example, \ref QCPBars apparent data
  3638. values can be shifted depending on their stacking, bar grouping or configured base value.
  3639. */
  3640. /*! \fn virtual bool QCPPlottableInterface1D::sortKeyIsMainKey() const = 0
  3641. Returns whether the sort key (\ref dataSortKey) is identical to the main key (\ref dataMainKey).
  3642. What the sort and main keys are, is defined by the plottable's data type. See the \ref
  3643. qcpdatacontainer-datatype "QCPDataContainer DataType" documentation for details about this naming
  3644. convention.
  3645. */
  3646. /*! \fn virtual int QCPPlottableInterface1D::findBegin(double sortKey, bool expandedRange) const = 0
  3647. Returns the index of the data point with a (sort-)key that is equal to, just below, or just above
  3648. \a sortKey. If \a expandedRange is true, the data point just below \a sortKey will be considered,
  3649. otherwise the one just above.
  3650. This can be used in conjunction with \ref findEnd to iterate over data points within a given key
  3651. range, including or excluding the bounding data points that are just beyond the specified range.
  3652. If \a expandedRange is true but there are no data points below \a sortKey, 0 is returned.
  3653. If the container is empty, returns 0 (in that case, \ref findEnd will also return 0, so a loop
  3654. using these methods will not iterate over the index 0).
  3655. \see findEnd, QCPDataContainer::findBegin
  3656. */
  3657. /*! \fn virtual int QCPPlottableInterface1D::findEnd(double sortKey, bool expandedRange) const = 0
  3658. Returns the index one after the data point with a (sort-)key that is equal to, just above, or
  3659. just below \a sortKey. If \a expandedRange is true, the data point just above \a sortKey will be
  3660. considered, otherwise the one just below.
  3661. This can be used in conjunction with \ref findBegin to iterate over data points within a given
  3662. key range, including the bounding data points that are just below and above the specified range.
  3663. If \a expandedRange is true but there are no data points above \a sortKey, the index just above the
  3664. highest data point is returned.
  3665. If the container is empty, returns 0.
  3666. \see findBegin, QCPDataContainer::findEnd
  3667. */
  3668. /* end documentation of pure virtual functions */
  3669. ////////////////////////////////////////////////////////////////////////////////////////////////////
  3670. //////////////////// QCPAbstractPlottable1D
  3671. ////////////////////////////////////////////////////////////////////////////////////////////////////
  3672. /*! \class QCPAbstractPlottable1D
  3673. \brief A template base class for plottables with one-dimensional data
  3674. This template class derives from \ref QCPAbstractPlottable and from the abstract interface \ref
  3675. QCPPlottableInterface1D. It serves as a base class for all one-dimensional data (i.e. data with
  3676. one key dimension), such as \ref QCPGraph and QCPCurve.
  3677. The template parameter \a DataType is the type of the data points of this plottable (e.g. \ref
  3678. QCPGraphData or \ref QCPCurveData). The main purpose of this base class is to provide the member
  3679. \a mDataContainer (a shared pointer to a \ref QCPDataContainer "QCPDataContainer<DataType>") and
  3680. implement the according virtual methods of the \ref QCPPlottableInterface1D, such that most
  3681. subclassed plottables don't need to worry about this anymore.
  3682. Further, it provides a convenience method for retrieving selected/unselected data segments via
  3683. \ref getDataSegments. This is useful when subclasses implement their \ref draw method and need to
  3684. draw selected segments with a different pen/brush than unselected segments (also see \ref
  3685. QCPSelectionDecorator).
  3686. This class implements basic functionality of \ref QCPAbstractPlottable::selectTest and \ref
  3687. QCPPlottableInterface1D::selectTestRect, assuming point-like data points, based on the 1D data
  3688. interface. In spite of that, most plottable subclasses will want to reimplement those methods
  3689. again, to provide a more accurate hit test based on their specific data visualization geometry.
  3690. */
  3691. /* start documentation of inline functions */
  3692. /*! \fn QCPPlottableInterface1D *QCPAbstractPlottable1D::interface1D()
  3693. Returns a \ref QCPPlottableInterface1D pointer to this plottable, providing access to its 1D
  3694. interface.
  3695. \seebaseclassmethod
  3696. */
  3697. /* end documentation of inline functions */
  3698. /*!
  3699. Forwards \a keyAxis and \a valueAxis to the \ref QCPAbstractPlottable::QCPAbstractPlottable
  3700. "QCPAbstractPlottable" constructor and allocates the \a mDataContainer.
  3701. */
  3702. template <class DataType>
  3703. QCPAbstractPlottable1D<DataType>::QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis) :
  3704. QCPAbstractPlottable(keyAxis, valueAxis),
  3705. mDataContainer(new QCPDataContainer<DataType>)
  3706. {
  3707. }
  3708. template <class DataType>
  3709. QCPAbstractPlottable1D<DataType>::~QCPAbstractPlottable1D()
  3710. {
  3711. }
  3712. /*!
  3713. \copydoc QCPPlottableInterface1D::dataCount
  3714. */
  3715. template <class DataType>
  3716. int QCPAbstractPlottable1D<DataType>::dataCount() const
  3717. {
  3718. return mDataContainer->size();
  3719. }
  3720. /*!
  3721. \copydoc QCPPlottableInterface1D::dataMainKey
  3722. */
  3723. template <class DataType>
  3724. double QCPAbstractPlottable1D<DataType>::dataMainKey(int index) const
  3725. {
  3726. if (index >= 0 && index < mDataContainer->size())
  3727. {
  3728. return (mDataContainer->constBegin()+index)->mainKey();
  3729. } else
  3730. {
  3731. qDebug() << Q_FUNC_INFO << "Index out of bounds" << index;
  3732. return 0;
  3733. }
  3734. }
  3735. /*!
  3736. \copydoc QCPPlottableInterface1D::dataSortKey
  3737. */
  3738. template <class DataType>
  3739. double QCPAbstractPlottable1D<DataType>::dataSortKey(int index) const
  3740. {
  3741. if (index >= 0 && index < mDataContainer->size())
  3742. {
  3743. return (mDataContainer->constBegin()+index)->sortKey();
  3744. } else
  3745. {
  3746. qDebug() << Q_FUNC_INFO << "Index out of bounds" << index;
  3747. return 0;
  3748. }
  3749. }
  3750. /*!
  3751. \copydoc QCPPlottableInterface1D::dataMainValue
  3752. */
  3753. template <class DataType>
  3754. double QCPAbstractPlottable1D<DataType>::dataMainValue(int index) const
  3755. {
  3756. if (index >= 0 && index < mDataContainer->size())
  3757. {
  3758. return (mDataContainer->constBegin()+index)->mainValue();
  3759. } else
  3760. {
  3761. qDebug() << Q_FUNC_INFO << "Index out of bounds" << index;
  3762. return 0;
  3763. }
  3764. }
  3765. /*!
  3766. \copydoc QCPPlottableInterface1D::dataValueRange
  3767. */
  3768. template <class DataType>
  3769. QCPRange QCPAbstractPlottable1D<DataType>::dataValueRange(int index) const
  3770. {
  3771. if (index >= 0 && index < mDataContainer->size())
  3772. {
  3773. return (mDataContainer->constBegin()+index)->valueRange();
  3774. } else
  3775. {
  3776. qDebug() << Q_FUNC_INFO << "Index out of bounds" << index;
  3777. return QCPRange(0, 0);
  3778. }
  3779. }
  3780. /*!
  3781. \copydoc QCPPlottableInterface1D::dataPixelPosition
  3782. */
  3783. template <class DataType>
  3784. QPointF QCPAbstractPlottable1D<DataType>::dataPixelPosition(int index) const
  3785. {
  3786. if (index >= 0 && index < mDataContainer->size())
  3787. {
  3788. const typename QCPDataContainer<DataType>::const_iterator it = mDataContainer->constBegin()+index;
  3789. return coordsToPixels(it->mainKey(), it->mainValue());
  3790. } else
  3791. {
  3792. qDebug() << Q_FUNC_INFO << "Index out of bounds" << index;
  3793. return QPointF();
  3794. }
  3795. }
  3796. /*!
  3797. \copydoc QCPPlottableInterface1D::sortKeyIsMainKey
  3798. */
  3799. template <class DataType>
  3800. bool QCPAbstractPlottable1D<DataType>::sortKeyIsMainKey() const
  3801. {
  3802. return DataType::sortKeyIsMainKey();
  3803. }
  3804. /*!
  3805. Implements a rect-selection algorithm assuming the data (accessed via the 1D data interface) is
  3806. point-like. Most subclasses will want to reimplement this method again, to provide a more
  3807. accurate hit test based on the true data visualization geometry.
  3808. \seebaseclassmethod
  3809. */
  3810. template <class DataType>
  3811. QCPDataSelection QCPAbstractPlottable1D<DataType>::selectTestRect(const QRectF &rect, bool onlySelectable) const
  3812. {
  3813. QCPDataSelection result;
  3814. if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty())
  3815. return result;
  3816. if (!mKeyAxis || !mValueAxis)
  3817. return result;
  3818. // convert rect given in pixels to ranges given in plot coordinates:
  3819. double key1, value1, key2, value2;
  3820. pixelsToCoords(rect.topLeft(), key1, value1);
  3821. pixelsToCoords(rect.bottomRight(), key2, value2);
  3822. QCPRange keyRange(key1, key2); // QCPRange normalizes internally so we don't have to care about whether key1 < key2
  3823. QCPRange valueRange(value1, value2);
  3824. typename QCPDataContainer<DataType>::const_iterator begin = mDataContainer->constBegin();
  3825. typename QCPDataContainer<DataType>::const_iterator end = mDataContainer->constEnd();
  3826. if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval:
  3827. {
  3828. begin = mDataContainer->findBegin(keyRange.lower, false);
  3829. end = mDataContainer->findEnd(keyRange.upper, false);
  3830. }
  3831. if (begin == end)
  3832. return result;
  3833. int currentSegmentBegin = -1; // -1 means we're currently not in a segment that's contained in rect
  3834. for (typename QCPDataContainer<DataType>::const_iterator it=begin; it!=end; ++it)
  3835. {
  3836. if (currentSegmentBegin == -1)
  3837. {
  3838. if (valueRange.contains(it->mainValue()) && keyRange.contains(it->mainKey())) // start segment
  3839. currentSegmentBegin = int(it-mDataContainer->constBegin());
  3840. } else if (!valueRange.contains(it->mainValue()) || !keyRange.contains(it->mainKey())) // segment just ended
  3841. {
  3842. result.addDataRange(QCPDataRange(currentSegmentBegin, int(it-mDataContainer->constBegin())), false);
  3843. currentSegmentBegin = -1;
  3844. }
  3845. }
  3846. // process potential last segment:
  3847. if (currentSegmentBegin != -1)
  3848. result.addDataRange(QCPDataRange(currentSegmentBegin, int(end-mDataContainer->constBegin())), false);
  3849. result.simplify();
  3850. return result;
  3851. }
  3852. /*!
  3853. \copydoc QCPPlottableInterface1D::findBegin
  3854. */
  3855. template <class DataType>
  3856. int QCPAbstractPlottable1D<DataType>::findBegin(double sortKey, bool expandedRange) const
  3857. {
  3858. return int(mDataContainer->findBegin(sortKey, expandedRange)-mDataContainer->constBegin());
  3859. }
  3860. /*!
  3861. \copydoc QCPPlottableInterface1D::findEnd
  3862. */
  3863. template <class DataType>
  3864. int QCPAbstractPlottable1D<DataType>::findEnd(double sortKey, bool expandedRange) const
  3865. {
  3866. return int(mDataContainer->findEnd(sortKey, expandedRange)-mDataContainer->constBegin());
  3867. }
  3868. /*!
  3869. Implements a point-selection algorithm assuming the data (accessed via the 1D data interface) is
  3870. point-like. Most subclasses will want to reimplement this method again, to provide a more
  3871. accurate hit test based on the true data visualization geometry.
  3872. If \a details is not 0, it will be set to a \ref QCPDataSelection, describing the closest data point
  3873. to \a pos.
  3874. \seebaseclassmethod
  3875. */
  3876. template <class DataType>
  3877. double QCPAbstractPlottable1D<DataType>::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const
  3878. {
  3879. if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty())
  3880. return -1;
  3881. if (!mKeyAxis || !mValueAxis)
  3882. return -1;
  3883. QCPDataSelection selectionResult;
  3884. double minDistSqr = (std::numeric_limits<double>::max)();
  3885. int minDistIndex = mDataContainer->size();
  3886. typename QCPDataContainer<DataType>::const_iterator begin = mDataContainer->constBegin();
  3887. typename QCPDataContainer<DataType>::const_iterator end = mDataContainer->constEnd();
  3888. if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval:
  3889. {
  3890. // determine which key range comes into question, taking selection tolerance around pos into account:
  3891. double posKeyMin, posKeyMax, dummy;
  3892. pixelsToCoords(pos-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy);
  3893. pixelsToCoords(pos+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy);
  3894. if (posKeyMin > posKeyMax)
  3895. qSwap(posKeyMin, posKeyMax);
  3896. begin = mDataContainer->findBegin(posKeyMin, true);
  3897. end = mDataContainer->findEnd(posKeyMax, true);
  3898. }
  3899. if (begin == end)
  3900. return -1;
  3901. QCPRange keyRange(mKeyAxis->range());
  3902. QCPRange valueRange(mValueAxis->range());
  3903. for (typename QCPDataContainer<DataType>::const_iterator it=begin; it!=end; ++it)
  3904. {
  3905. const double mainKey = it->mainKey();
  3906. const double mainValue = it->mainValue();
  3907. if (keyRange.contains(mainKey) && valueRange.contains(mainValue)) // make sure data point is inside visible range, for speedup in cases where sort key isn't main key and we iterate over all points
  3908. {
  3909. const double currentDistSqr = QCPVector2D(coordsToPixels(mainKey, mainValue)-pos).lengthSquared();
  3910. if (currentDistSqr < minDistSqr)
  3911. {
  3912. minDistSqr = currentDistSqr;
  3913. minDistIndex = int(it-mDataContainer->constBegin());
  3914. }
  3915. }
  3916. }
  3917. if (minDistIndex != mDataContainer->size())
  3918. selectionResult.addDataRange(QCPDataRange(minDistIndex, minDistIndex+1), false);
  3919. selectionResult.simplify();
  3920. if (details)
  3921. details->setValue(selectionResult);
  3922. return qSqrt(minDistSqr);
  3923. }
  3924. /*!
  3925. Splits all data into selected and unselected segments and outputs them via \a selectedSegments
  3926. and \a unselectedSegments, respectively.
  3927. This is useful when subclasses implement their \ref draw method and need to draw selected
  3928. segments with a different pen/brush than unselected segments (also see \ref
  3929. QCPSelectionDecorator).
  3930. \see setSelection
  3931. */
  3932. template <class DataType>
  3933. void QCPAbstractPlottable1D<DataType>::getDataSegments(QList<QCPDataRange> &selectedSegments, QList<QCPDataRange> &unselectedSegments) const
  3934. {
  3935. selectedSegments.clear();
  3936. unselectedSegments.clear();
  3937. if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty
  3938. {
  3939. if (selected())
  3940. selectedSegments << QCPDataRange(0, dataCount());
  3941. else
  3942. unselectedSegments << QCPDataRange(0, dataCount());
  3943. } else
  3944. {
  3945. QCPDataSelection sel(selection());
  3946. sel.simplify();
  3947. selectedSegments = sel.dataRanges();
  3948. unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges();
  3949. }
  3950. }
  3951. /*!
  3952. A helper method which draws a line with the passed \a painter, according to the pixel data in \a
  3953. lineData. NaN points create gaps in the line, as expected from QCustomPlot's plottables (this is
  3954. the main difference to QPainter's regular drawPolyline, which handles NaNs by lagging or
  3955. crashing).
  3956. Further it uses a faster line drawing technique based on \ref QCPPainter::drawLine rather than \c
  3957. QPainter::drawPolyline if the configured \ref QCustomPlot::setPlottingHints() and \a painter
  3958. style allows.
  3959. */
  3960. template <class DataType>
  3961. void QCPAbstractPlottable1D<DataType>::drawPolyline(QCPPainter *painter, const QVector<QPointF> &lineData) const
  3962. {
  3963. // if drawing lines in plot (instead of PDF), reduce 1px lines to cosmetic, because at least in
  3964. // Qt6 drawing of "1px" width lines is much slower even though it has same appearance apart from
  3965. // High-DPI. In High-DPI cases people must set a pen width slightly larger than 1.0 to get
  3966. // correct DPI scaling of width, but of course with performance penalty.
  3967. if (!painter->modes().testFlag(QCPPainter::pmVectorized) &&
  3968. qFuzzyCompare(painter->pen().widthF(), 1.0))
  3969. {
  3970. QPen newPen = painter->pen();
  3971. newPen.setWidth(0);
  3972. painter->setPen(newPen);
  3973. }
  3974. // if drawing solid line and not in PDF, use much faster line drawing instead of polyline:
  3975. if (mParentPlot->plottingHints().testFlag(QCP::phFastPolylines) &&
  3976. painter->pen().style() == Qt::SolidLine &&
  3977. !painter->modes().testFlag(QCPPainter::pmVectorized) &&
  3978. !painter->modes().testFlag(QCPPainter::pmNoCaching))
  3979. {
  3980. int i = 0;
  3981. bool lastIsNan = false;
  3982. const int lineDataSize = lineData.size();
  3983. while (i < lineDataSize && (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()))) // make sure first point is not NaN
  3984. ++i;
  3985. ++i; // because drawing works in 1 point retrospect
  3986. while (i < lineDataSize)
  3987. {
  3988. if (!qIsNaN(lineData.at(i).y()) && !qIsNaN(lineData.at(i).x())) // NaNs create a gap in the line
  3989. {
  3990. if (!lastIsNan)
  3991. painter->drawLine(lineData.at(i-1), lineData.at(i));
  3992. else
  3993. lastIsNan = false;
  3994. } else
  3995. lastIsNan = true;
  3996. ++i;
  3997. }
  3998. } else
  3999. {
  4000. int segmentStart = 0;
  4001. int i = 0;
  4002. const int lineDataSize = lineData.size();
  4003. while (i < lineDataSize)
  4004. {
  4005. if (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()) || qIsInf(lineData.at(i).y())) // NaNs create a gap in the line. Also filter Infs which make drawPolyline block
  4006. {
  4007. painter->drawPolyline(lineData.constData()+segmentStart, i-segmentStart); // i, because we don't want to include the current NaN point
  4008. segmentStart = i+1;
  4009. }
  4010. ++i;
  4011. }
  4012. // draw last segment:
  4013. painter->drawPolyline(lineData.constData()+segmentStart, lineDataSize-segmentStart);
  4014. }
  4015. }
  4016. /* end of 'src/plottable1d.h' */
  4017. /* including file 'src/colorgradient.h' */
  4018. /* modified 2022-11-06T12:45:56, size 7262 */
  4019. class QCP_LIB_DECL QCPColorGradient
  4020. {
  4021. Q_GADGET
  4022. public:
  4023. /*!
  4024. Defines the color spaces in which color interpolation between gradient stops can be performed.
  4025. \see setColorInterpolation
  4026. */
  4027. enum ColorInterpolation { ciRGB ///< Color channels red, green and blue are linearly interpolated
  4028. ,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance)
  4029. };
  4030. Q_ENUMS(ColorInterpolation)
  4031. /*!
  4032. Defines how NaN data points shall appear in the plot.
  4033. \see setNanHandling, setNanColor
  4034. */
  4035. enum NanHandling { nhNone ///< NaN data points are not explicitly handled and shouldn't occur in the data (this gives slight performance improvement)
  4036. ,nhLowestColor ///< NaN data points appear as the lowest color defined in this QCPColorGradient
  4037. ,nhHighestColor ///< NaN data points appear as the highest color defined in this QCPColorGradient
  4038. ,nhTransparent ///< NaN data points appear transparent
  4039. ,nhNanColor ///< NaN data points appear as the color defined with \ref setNanColor
  4040. };
  4041. Q_ENUMS(NanHandling)
  4042. /*!
  4043. Defines the available presets that can be loaded with \ref loadPreset. See the documentation
  4044. there for an image of the presets.
  4045. */
  4046. enum GradientPreset { gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation)
  4047. ,gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation)
  4048. ,gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation)
  4049. ,gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation)
  4050. ,gpCandy ///< Blue over pink to white
  4051. ,gpGeography ///< Colors suitable to represent different elevations on geographical maps
  4052. ,gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates)
  4053. ,gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white
  4054. ,gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values
  4055. ,gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates)
  4056. ,gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates)
  4057. ,gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic)
  4058. };
  4059. Q_ENUMS(GradientPreset)
  4060. QCPColorGradient();
  4061. QCPColorGradient(GradientPreset preset);
  4062. bool operator==(const QCPColorGradient &other) const;
  4063. bool operator!=(const QCPColorGradient &other) const { return !(*this == other); }
  4064. // getters:
  4065. int levelCount() const { return mLevelCount; }
  4066. QMap<double, QColor> colorStops() const { return mColorStops; }
  4067. ColorInterpolation colorInterpolation() const { return mColorInterpolation; }
  4068. NanHandling nanHandling() const { return mNanHandling; }
  4069. QColor nanColor() const { return mNanColor; }
  4070. bool periodic() const { return mPeriodic; }
  4071. // setters:
  4072. void setLevelCount(int n);
  4073. void setColorStops(const QMap<double, QColor> &colorStops);
  4074. void setColorStopAt(double position, const QColor &color);
  4075. void setColorInterpolation(ColorInterpolation interpolation);
  4076. void setNanHandling(NanHandling handling);
  4077. void setNanColor(const QColor &color);
  4078. void setPeriodic(bool enabled);
  4079. // non-property methods:
  4080. void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false);
  4081. void colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false);
  4082. QRgb color(double position, const QCPRange &range, bool logarithmic=false);
  4083. void loadPreset(GradientPreset preset);
  4084. void clearColorStops();
  4085. QCPColorGradient inverted() const;
  4086. protected:
  4087. // property members:
  4088. int mLevelCount;
  4089. QMap<double, QColor> mColorStops;
  4090. ColorInterpolation mColorInterpolation;
  4091. NanHandling mNanHandling;
  4092. QColor mNanColor;
  4093. bool mPeriodic;
  4094. // non-property members:
  4095. QVector<QRgb> mColorBuffer; // have colors premultiplied with alpha (for usage with QImage::Format_ARGB32_Premultiplied)
  4096. bool mColorBufferInvalidated;
  4097. // non-virtual methods:
  4098. bool stopsUseAlpha() const;
  4099. void updateColorBuffer();
  4100. };
  4101. Q_DECLARE_METATYPE(QCPColorGradient::ColorInterpolation)
  4102. Q_DECLARE_METATYPE(QCPColorGradient::NanHandling)
  4103. Q_DECLARE_METATYPE(QCPColorGradient::GradientPreset)
  4104. /* end of 'src/colorgradient.h' */
  4105. /* including file 'src/selectiondecorator-bracket.h' */
  4106. /* modified 2022-11-06T12:45:56, size 4458 */
  4107. class QCP_LIB_DECL QCPSelectionDecoratorBracket : public QCPSelectionDecorator
  4108. {
  4109. Q_GADGET
  4110. public:
  4111. /*!
  4112. Defines which shape is drawn at the boundaries of selected data ranges.
  4113. Some of the bracket styles further allow specifying a height and/or width, see \ref
  4114. setBracketHeight and \ref setBracketWidth.
  4115. */
  4116. enum BracketStyle { bsSquareBracket ///< A square bracket is drawn.
  4117. ,bsHalfEllipse ///< A half ellipse is drawn. The size of the ellipse is given by the bracket width/height properties.
  4118. ,bsEllipse ///< An ellipse is drawn. The size of the ellipse is given by the bracket width/height properties.
  4119. ,bsPlus ///< A plus is drawn.
  4120. ,bsUserStyle ///< Start custom bracket styles at this index when subclassing and reimplementing \ref drawBracket.
  4121. };
  4122. Q_ENUMS(BracketStyle)
  4123. QCPSelectionDecoratorBracket();
  4124. virtual ~QCPSelectionDecoratorBracket() Q_DECL_OVERRIDE;
  4125. // getters:
  4126. QPen bracketPen() const { return mBracketPen; }
  4127. QBrush bracketBrush() const { return mBracketBrush; }
  4128. int bracketWidth() const { return mBracketWidth; }
  4129. int bracketHeight() const { return mBracketHeight; }
  4130. BracketStyle bracketStyle() const { return mBracketStyle; }
  4131. bool tangentToData() const { return mTangentToData; }
  4132. int tangentAverage() const { return mTangentAverage; }
  4133. // setters:
  4134. void setBracketPen(const QPen &pen);
  4135. void setBracketBrush(const QBrush &brush);
  4136. void setBracketWidth(int width);
  4137. void setBracketHeight(int height);
  4138. void setBracketStyle(BracketStyle style);
  4139. void setTangentToData(bool enabled);
  4140. void setTangentAverage(int pointCount);
  4141. // introduced virtual methods:
  4142. virtual void drawBracket(QCPPainter *painter, int direction) const;
  4143. // virtual methods:
  4144. virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection) Q_DECL_OVERRIDE;
  4145. protected:
  4146. // property members:
  4147. QPen mBracketPen;
  4148. QBrush mBracketBrush;
  4149. int mBracketWidth;
  4150. int mBracketHeight;
  4151. BracketStyle mBracketStyle;
  4152. bool mTangentToData;
  4153. int mTangentAverage;
  4154. // non-virtual methods:
  4155. double getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const;
  4156. QPointF getPixelCoordinates(const QCPPlottableInterface1D *interface1d, int dataIndex) const;
  4157. };
  4158. Q_DECLARE_METATYPE(QCPSelectionDecoratorBracket::BracketStyle)
  4159. /* end of 'src/selectiondecorator-bracket.h' */
  4160. /* including file 'src/layoutelements/layoutelement-axisrect.h' */
  4161. /* modified 2022-11-06T12:45:56, size 7529 */
  4162. class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement
  4163. {
  4164. Q_OBJECT
  4165. /// \cond INCLUDE_QPROPERTIES
  4166. Q_PROPERTY(QPixmap background READ background WRITE setBackground)
  4167. Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
  4168. Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
  4169. Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag)
  4170. Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom)
  4171. /// \endcond
  4172. public:
  4173. explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true);
  4174. virtual ~QCPAxisRect() Q_DECL_OVERRIDE;
  4175. // getters:
  4176. QPixmap background() const { return mBackgroundPixmap; }
  4177. QBrush backgroundBrush() const { return mBackgroundBrush; }
  4178. bool backgroundScaled() const { return mBackgroundScaled; }
  4179. Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
  4180. Qt::Orientations rangeDrag() const { return mRangeDrag; }
  4181. Qt::Orientations rangeZoom() const { return mRangeZoom; }
  4182. QCPAxis *rangeDragAxis(Qt::Orientation orientation);
  4183. QCPAxis *rangeZoomAxis(Qt::Orientation orientation);
  4184. QList<QCPAxis*> rangeDragAxes(Qt::Orientation orientation);
  4185. QList<QCPAxis*> rangeZoomAxes(Qt::Orientation orientation);
  4186. double rangeZoomFactor(Qt::Orientation orientation);
  4187. // setters:
  4188. void setBackground(const QPixmap &pm);
  4189. void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
  4190. void setBackground(const QBrush &brush);
  4191. void setBackgroundScaled(bool scaled);
  4192. void setBackgroundScaledMode(Qt::AspectRatioMode mode);
  4193. void setRangeDrag(Qt::Orientations orientations);
  4194. void setRangeZoom(Qt::Orientations orientations);
  4195. void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical);
  4196. void setRangeDragAxes(QList<QCPAxis*> axes);
  4197. void setRangeDragAxes(QList<QCPAxis*> horizontal, QList<QCPAxis*> vertical);
  4198. void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical);
  4199. void setRangeZoomAxes(QList<QCPAxis*> axes);
  4200. void setRangeZoomAxes(QList<QCPAxis*> horizontal, QList<QCPAxis*> vertical);
  4201. void setRangeZoomFactor(double horizontalFactor, double verticalFactor);
  4202. void setRangeZoomFactor(double factor);
  4203. // non-property methods:
  4204. int axisCount(QCPAxis::AxisType type) const;
  4205. QCPAxis *axis(QCPAxis::AxisType type, int index=0) const;
  4206. QList<QCPAxis*> axes(QCPAxis::AxisTypes types) const;
  4207. QList<QCPAxis*> axes() const;
  4208. QCPAxis *addAxis(QCPAxis::AxisType type, QCPAxis *axis=nullptr);
  4209. QList<QCPAxis*> addAxes(QCPAxis::AxisTypes types);
  4210. bool removeAxis(QCPAxis *axis);
  4211. QCPLayoutInset *insetLayout() const { return mInsetLayout; }
  4212. void zoom(const QRectF &pixelRect);
  4213. void zoom(const QRectF &pixelRect, const QList<QCPAxis*> &affectedAxes);
  4214. void setupFullAxesBox(bool connectRanges=false);
  4215. QList<QCPAbstractPlottable*> plottables() const;
  4216. QList<QCPGraph*> graphs() const;
  4217. QList<QCPAbstractItem*> items() const;
  4218. // read-only interface imitating a QRect:
  4219. int left() const { return mRect.left(); }
  4220. int right() const { return mRect.right(); }
  4221. int top() const { return mRect.top(); }
  4222. int bottom() const { return mRect.bottom(); }
  4223. int width() const { return mRect.width(); }
  4224. int height() const { return mRect.height(); }
  4225. QSize size() const { return mRect.size(); }
  4226. QPoint topLeft() const { return mRect.topLeft(); }
  4227. QPoint topRight() const { return mRect.topRight(); }
  4228. QPoint bottomLeft() const { return mRect.bottomLeft(); }
  4229. QPoint bottomRight() const { return mRect.bottomRight(); }
  4230. QPoint center() const { return mRect.center(); }
  4231. // reimplemented virtual methods:
  4232. virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE;
  4233. virtual QList<QCPLayoutElement*> elements(bool recursive) const Q_DECL_OVERRIDE;
  4234. protected:
  4235. // property members:
  4236. QBrush mBackgroundBrush;
  4237. QPixmap mBackgroundPixmap;
  4238. QPixmap mScaledBackgroundPixmap;
  4239. bool mBackgroundScaled;
  4240. Qt::AspectRatioMode mBackgroundScaledMode;
  4241. QCPLayoutInset *mInsetLayout;
  4242. Qt::Orientations mRangeDrag, mRangeZoom;
  4243. QList<QPointer<QCPAxis> > mRangeDragHorzAxis, mRangeDragVertAxis;
  4244. QList<QPointer<QCPAxis> > mRangeZoomHorzAxis, mRangeZoomVertAxis;
  4245. double mRangeZoomFactorHorz, mRangeZoomFactorVert;
  4246. // non-property members:
  4247. QList<QCPRange> mDragStartHorzRange, mDragStartVertRange;
  4248. QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
  4249. bool mDragging;
  4250. QHash<QCPAxis::AxisType, QList<QCPAxis*> > mAxes;
  4251. // reimplemented virtual methods:
  4252. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  4253. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  4254. virtual int calculateAutoMargin(QCP::MarginSide side) Q_DECL_OVERRIDE;
  4255. virtual void layoutChanged() Q_DECL_OVERRIDE;
  4256. // events:
  4257. virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE;
  4258. virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE;
  4259. virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE;
  4260. virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
  4261. // non-property methods:
  4262. void drawBackground(QCPPainter *painter);
  4263. void updateAxesOffset(QCPAxis::AxisType type);
  4264. private:
  4265. Q_DISABLE_COPY(QCPAxisRect)
  4266. friend class QCustomPlot;
  4267. };
  4268. /* end of 'src/layoutelements/layoutelement-axisrect.h' */
  4269. /* including file 'src/layoutelements/layoutelement-legend.h' */
  4270. /* modified 2022-11-06T12:45:56, size 10425 */
  4271. class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement
  4272. {
  4273. Q_OBJECT
  4274. /// \cond INCLUDE_QPROPERTIES
  4275. Q_PROPERTY(QCPLegend* parentLegend READ parentLegend)
  4276. Q_PROPERTY(QFont font READ font WRITE setFont)
  4277. Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
  4278. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  4279. Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
  4280. Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged)
  4281. Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged)
  4282. /// \endcond
  4283. public:
  4284. explicit QCPAbstractLegendItem(QCPLegend *parent);
  4285. // getters:
  4286. QCPLegend *parentLegend() const { return mParentLegend; }
  4287. QFont font() const { return mFont; }
  4288. QColor textColor() const { return mTextColor; }
  4289. QFont selectedFont() const { return mSelectedFont; }
  4290. QColor selectedTextColor() const { return mSelectedTextColor; }
  4291. bool selectable() const { return mSelectable; }
  4292. bool selected() const { return mSelected; }
  4293. // setters:
  4294. void setFont(const QFont &font);
  4295. void setTextColor(const QColor &color);
  4296. void setSelectedFont(const QFont &font);
  4297. void setSelectedTextColor(const QColor &color);
  4298. Q_SLOT void setSelectable(bool selectable);
  4299. Q_SLOT void setSelected(bool selected);
  4300. // reimplemented virtual methods:
  4301. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  4302. signals:
  4303. void selectionChanged(bool selected);
  4304. void selectableChanged(bool selectable);
  4305. protected:
  4306. // property members:
  4307. QCPLegend *mParentLegend;
  4308. QFont mFont;
  4309. QColor mTextColor;
  4310. QFont mSelectedFont;
  4311. QColor mSelectedTextColor;
  4312. bool mSelectable, mSelected;
  4313. // reimplemented virtual methods:
  4314. virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE;
  4315. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  4316. virtual QRect clipRect() const Q_DECL_OVERRIDE;
  4317. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0;
  4318. // events:
  4319. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE;
  4320. virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE;
  4321. private:
  4322. Q_DISABLE_COPY(QCPAbstractLegendItem)
  4323. friend class QCPLegend;
  4324. };
  4325. class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem
  4326. {
  4327. Q_OBJECT
  4328. public:
  4329. QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable);
  4330. // getters:
  4331. QCPAbstractPlottable *plottable() { return mPlottable; }
  4332. protected:
  4333. // property members:
  4334. QCPAbstractPlottable *mPlottable;
  4335. // reimplemented virtual methods:
  4336. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  4337. virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE;
  4338. // non-virtual methods:
  4339. QPen getIconBorderPen() const;
  4340. QColor getTextColor() const;
  4341. QFont getFont() const;
  4342. };
  4343. class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid
  4344. {
  4345. Q_OBJECT
  4346. /// \cond INCLUDE_QPROPERTIES
  4347. Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen)
  4348. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  4349. Q_PROPERTY(QFont font READ font WRITE setFont)
  4350. Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
  4351. Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
  4352. Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding)
  4353. Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen)
  4354. Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged)
  4355. Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged)
  4356. Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen)
  4357. Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen)
  4358. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  4359. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  4360. Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
  4361. /// \endcond
  4362. public:
  4363. /*!
  4364. Defines the selectable parts of a legend
  4365. \see setSelectedParts, setSelectableParts
  4366. */
  4367. enum SelectablePart { spNone = 0x000 ///< <tt>0x000</tt> None
  4368. ,spLegendBox = 0x001 ///< <tt>0x001</tt> The legend box (frame)
  4369. ,spItems = 0x002 ///< <tt>0x002</tt> Legend items individually (see \ref selectedItems)
  4370. };
  4371. Q_ENUMS(SelectablePart)
  4372. Q_FLAGS(SelectableParts)
  4373. Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
  4374. explicit QCPLegend();
  4375. virtual ~QCPLegend() Q_DECL_OVERRIDE;
  4376. // getters:
  4377. QPen borderPen() const { return mBorderPen; }
  4378. QBrush brush() const { return mBrush; }
  4379. QFont font() const { return mFont; }
  4380. QColor textColor() const { return mTextColor; }
  4381. QSize iconSize() const { return mIconSize; }
  4382. int iconTextPadding() const { return mIconTextPadding; }
  4383. QPen iconBorderPen() const { return mIconBorderPen; }
  4384. SelectableParts selectableParts() const { return mSelectableParts; }
  4385. SelectableParts selectedParts() const;
  4386. QPen selectedBorderPen() const { return mSelectedBorderPen; }
  4387. QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; }
  4388. QBrush selectedBrush() const { return mSelectedBrush; }
  4389. QFont selectedFont() const { return mSelectedFont; }
  4390. QColor selectedTextColor() const { return mSelectedTextColor; }
  4391. // setters:
  4392. void setBorderPen(const QPen &pen);
  4393. void setBrush(const QBrush &brush);
  4394. void setFont(const QFont &font);
  4395. void setTextColor(const QColor &color);
  4396. void setIconSize(const QSize &size);
  4397. void setIconSize(int width, int height);
  4398. void setIconTextPadding(int padding);
  4399. void setIconBorderPen(const QPen &pen);
  4400. Q_SLOT void setSelectableParts(const SelectableParts &selectableParts);
  4401. Q_SLOT void setSelectedParts(const SelectableParts &selectedParts);
  4402. void setSelectedBorderPen(const QPen &pen);
  4403. void setSelectedIconBorderPen(const QPen &pen);
  4404. void setSelectedBrush(const QBrush &brush);
  4405. void setSelectedFont(const QFont &font);
  4406. void setSelectedTextColor(const QColor &color);
  4407. // reimplemented virtual methods:
  4408. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  4409. // non-virtual methods:
  4410. QCPAbstractLegendItem *item(int index) const;
  4411. QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const;
  4412. int itemCount() const;
  4413. bool hasItem(QCPAbstractLegendItem *item) const;
  4414. bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const;
  4415. bool addItem(QCPAbstractLegendItem *item);
  4416. bool removeItem(int index);
  4417. bool removeItem(QCPAbstractLegendItem *item);
  4418. void clearItems();
  4419. QList<QCPAbstractLegendItem*> selectedItems() const;
  4420. signals:
  4421. void selectionChanged(QCPLegend::SelectableParts parts);
  4422. void selectableChanged(QCPLegend::SelectableParts parts);
  4423. protected:
  4424. // property members:
  4425. QPen mBorderPen, mIconBorderPen;
  4426. QBrush mBrush;
  4427. QFont mFont;
  4428. QColor mTextColor;
  4429. QSize mIconSize;
  4430. int mIconTextPadding;
  4431. SelectableParts mSelectedParts, mSelectableParts;
  4432. QPen mSelectedBorderPen, mSelectedIconBorderPen;
  4433. QBrush mSelectedBrush;
  4434. QFont mSelectedFont;
  4435. QColor mSelectedTextColor;
  4436. // reimplemented virtual methods:
  4437. virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE;
  4438. virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE;
  4439. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  4440. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  4441. // events:
  4442. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE;
  4443. virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE;
  4444. // non-virtual methods:
  4445. QPen getBorderPen() const;
  4446. QBrush getBrush() const;
  4447. private:
  4448. Q_DISABLE_COPY(QCPLegend)
  4449. friend class QCustomPlot;
  4450. friend class QCPAbstractLegendItem;
  4451. };
  4452. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts)
  4453. Q_DECLARE_METATYPE(QCPLegend::SelectablePart)
  4454. /* end of 'src/layoutelements/layoutelement-legend.h' */
  4455. /* including file 'src/layoutelements/layoutelement-textelement.h' */
  4456. /* modified 2022-11-06T12:45:56, size 5359 */
  4457. class QCP_LIB_DECL QCPTextElement : public QCPLayoutElement
  4458. {
  4459. Q_OBJECT
  4460. /// \cond INCLUDE_QPROPERTIES
  4461. Q_PROPERTY(QString text READ text WRITE setText)
  4462. Q_PROPERTY(QFont font READ font WRITE setFont)
  4463. Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
  4464. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  4465. Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
  4466. Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
  4467. Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
  4468. /// \endcond
  4469. public:
  4470. explicit QCPTextElement(QCustomPlot *parentPlot);
  4471. QCPTextElement(QCustomPlot *parentPlot, const QString &text);
  4472. QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize);
  4473. QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize);
  4474. QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font);
  4475. // getters:
  4476. QString text() const { return mText; }
  4477. int textFlags() const { return mTextFlags; }
  4478. QFont font() const { return mFont; }
  4479. QColor textColor() const { return mTextColor; }
  4480. QFont selectedFont() const { return mSelectedFont; }
  4481. QColor selectedTextColor() const { return mSelectedTextColor; }
  4482. bool selectable() const { return mSelectable; }
  4483. bool selected() const { return mSelected; }
  4484. // setters:
  4485. void setText(const QString &text);
  4486. void setTextFlags(int flags);
  4487. void setFont(const QFont &font);
  4488. void setTextColor(const QColor &color);
  4489. void setSelectedFont(const QFont &font);
  4490. void setSelectedTextColor(const QColor &color);
  4491. Q_SLOT void setSelectable(bool selectable);
  4492. Q_SLOT void setSelected(bool selected);
  4493. // reimplemented virtual methods:
  4494. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  4495. virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE;
  4496. virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE;
  4497. virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE;
  4498. signals:
  4499. void selectionChanged(bool selected);
  4500. void selectableChanged(bool selectable);
  4501. void clicked(QMouseEvent *event);
  4502. void doubleClicked(QMouseEvent *event);
  4503. protected:
  4504. // property members:
  4505. QString mText;
  4506. int mTextFlags;
  4507. QFont mFont;
  4508. QColor mTextColor;
  4509. QFont mSelectedFont;
  4510. QColor mSelectedTextColor;
  4511. QRect mTextBoundingRect;
  4512. bool mSelectable, mSelected;
  4513. // reimplemented virtual methods:
  4514. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  4515. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  4516. virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE;
  4517. virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE;
  4518. // events:
  4519. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE;
  4520. virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE;
  4521. // non-virtual methods:
  4522. QFont mainFont() const;
  4523. QColor mainTextColor() const;
  4524. private:
  4525. Q_DISABLE_COPY(QCPTextElement)
  4526. };
  4527. /* end of 'src/layoutelements/layoutelement-textelement.h' */
  4528. /* including file 'src/layoutelements/layoutelement-colorscale.h' */
  4529. /* modified 2022-11-06T12:45:56, size 5939 */
  4530. class QCPColorScaleAxisRectPrivate : public QCPAxisRect
  4531. {
  4532. Q_OBJECT
  4533. public:
  4534. explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale);
  4535. protected:
  4536. QCPColorScale *mParentColorScale;
  4537. QImage mGradientImage;
  4538. bool mGradientImageInvalidated;
  4539. // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale
  4540. using QCPAxisRect::calculateAutoMargin;
  4541. using QCPAxisRect::mousePressEvent;
  4542. using QCPAxisRect::mouseMoveEvent;
  4543. using QCPAxisRect::mouseReleaseEvent;
  4544. using QCPAxisRect::wheelEvent;
  4545. using QCPAxisRect::update;
  4546. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  4547. void updateGradientImage();
  4548. Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts);
  4549. Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts);
  4550. friend class QCPColorScale;
  4551. };
  4552. class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement
  4553. {
  4554. Q_OBJECT
  4555. /// \cond INCLUDE_QPROPERTIES
  4556. Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType)
  4557. Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
  4558. Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
  4559. Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
  4560. Q_PROPERTY(QString label READ label WRITE setLabel)
  4561. Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth)
  4562. Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag)
  4563. Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom)
  4564. /// \endcond
  4565. public:
  4566. explicit QCPColorScale(QCustomPlot *parentPlot);
  4567. virtual ~QCPColorScale() Q_DECL_OVERRIDE;
  4568. // getters:
  4569. QCPAxis *axis() const { return mColorAxis.data(); }
  4570. QCPAxis::AxisType type() const { return mType; }
  4571. QCPRange dataRange() const { return mDataRange; }
  4572. QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
  4573. QCPColorGradient gradient() const { return mGradient; }
  4574. QString label() const;
  4575. int barWidth () const { return mBarWidth; }
  4576. bool rangeDrag() const;
  4577. bool rangeZoom() const;
  4578. // setters:
  4579. void setType(QCPAxis::AxisType type);
  4580. Q_SLOT void setDataRange(const QCPRange &dataRange);
  4581. Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
  4582. Q_SLOT void setGradient(const QCPColorGradient &gradient);
  4583. void setLabel(const QString &str);
  4584. void setBarWidth(int width);
  4585. void setRangeDrag(bool enabled);
  4586. void setRangeZoom(bool enabled);
  4587. // non-property methods:
  4588. QList<QCPColorMap*> colorMaps() const;
  4589. void rescaleDataRange(bool onlyVisibleMaps);
  4590. // reimplemented virtual methods:
  4591. virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE;
  4592. signals:
  4593. void dataRangeChanged(const QCPRange &newRange);
  4594. void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
  4595. void gradientChanged(const QCPColorGradient &newGradient);
  4596. protected:
  4597. // property members:
  4598. QCPAxis::AxisType mType;
  4599. QCPRange mDataRange;
  4600. QCPAxis::ScaleType mDataScaleType;
  4601. QCPColorGradient mGradient;
  4602. int mBarWidth;
  4603. // non-property members:
  4604. QPointer<QCPColorScaleAxisRectPrivate> mAxisRect;
  4605. QPointer<QCPAxis> mColorAxis;
  4606. // reimplemented virtual methods:
  4607. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  4608. // events:
  4609. virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE;
  4610. virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE;
  4611. virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE;
  4612. virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
  4613. private:
  4614. Q_DISABLE_COPY(QCPColorScale)
  4615. friend class QCPColorScaleAxisRectPrivate;
  4616. };
  4617. /* end of 'src/layoutelements/layoutelement-colorscale.h' */
  4618. /* including file 'src/plottables/plottable-graph.h' */
  4619. /* modified 2022-11-06T12:45:56, size 9316 */
  4620. class QCP_LIB_DECL QCPGraphData
  4621. {
  4622. public:
  4623. QCPGraphData();
  4624. QCPGraphData(double key, double value);
  4625. inline double sortKey() const { return key; }
  4626. inline static QCPGraphData fromSortKey(double sortKey) { return QCPGraphData(sortKey, 0); }
  4627. inline static bool sortKeyIsMainKey() { return true; }
  4628. inline double mainKey() const { return key; }
  4629. inline double mainValue() const { return value; }
  4630. inline QCPRange valueRange() const { return QCPRange(value, value); }
  4631. double key, value;
  4632. };
  4633. Q_DECLARE_TYPEINFO(QCPGraphData, Q_PRIMITIVE_TYPE);
  4634. /*! \typedef QCPGraphDataContainer
  4635. Container for storing \ref QCPGraphData points. The data is stored sorted by \a key.
  4636. This template instantiation is the container in which QCPGraph holds its data. For details about
  4637. the generic container, see the documentation of the class template \ref QCPDataContainer.
  4638. \see QCPGraphData, QCPGraph::setData
  4639. */
  4640. typedef QCPDataContainer<QCPGraphData> QCPGraphDataContainer;
  4641. class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable1D<QCPGraphData>
  4642. {
  4643. Q_OBJECT
  4644. /// \cond INCLUDE_QPROPERTIES
  4645. Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
  4646. Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
  4647. Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip)
  4648. Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph)
  4649. Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling)
  4650. /// \endcond
  4651. public:
  4652. /*!
  4653. Defines how the graph's line is represented visually in the plot. The line is drawn with the
  4654. current pen of the graph (\ref setPen).
  4655. \see setLineStyle
  4656. */
  4657. enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented
  4658. ///< with symbols according to the scatter style, see \ref setScatterStyle)
  4659. ,lsLine ///< data points are connected by a straight line
  4660. ,lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point
  4661. ,lsStepRight ///< line is drawn as steps where the step height is the value of the right data point
  4662. ,lsStepCenter ///< line is drawn as steps where the step is in between two data points
  4663. ,lsImpulse ///< each data point is represented by a line parallel to the value axis, which reaches from the data point to the zero-value-line
  4664. };
  4665. Q_ENUMS(LineStyle)
  4666. explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis);
  4667. virtual ~QCPGraph() Q_DECL_OVERRIDE;
  4668. // getters:
  4669. QSharedPointer<QCPGraphDataContainer> data() const { return mDataContainer; }
  4670. LineStyle lineStyle() const { return mLineStyle; }
  4671. QCPScatterStyle scatterStyle() const { return mScatterStyle; }
  4672. int scatterSkip() const { return mScatterSkip; }
  4673. QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); }
  4674. bool adaptiveSampling() const { return mAdaptiveSampling; }
  4675. // setters:
  4676. void setData(QSharedPointer<QCPGraphDataContainer> data);
  4677. void setData(const QVector<double> &keys, const QVector<double> &values, bool alreadySorted=false);
  4678. void setLineStyle(LineStyle ls);
  4679. void setScatterStyle(const QCPScatterStyle &style);
  4680. void setScatterSkip(int skip);
  4681. void setChannelFillGraph(QCPGraph *targetGraph);
  4682. void setAdaptiveSampling(bool enabled);
  4683. // non-property methods:
  4684. void addData(const QVector<double> &keys, const QVector<double> &values, bool alreadySorted=false);
  4685. void addData(double key, double value);
  4686. // reimplemented virtual methods:
  4687. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  4688. virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE;
  4689. virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE;
  4690. protected:
  4691. // property members:
  4692. LineStyle mLineStyle;
  4693. QCPScatterStyle mScatterStyle;
  4694. int mScatterSkip;
  4695. QPointer<QCPGraph> mChannelFillGraph;
  4696. bool mAdaptiveSampling;
  4697. // reimplemented virtual methods:
  4698. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  4699. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE;
  4700. // introduced virtual methods:
  4701. virtual void drawFill(QCPPainter *painter, QVector<QPointF> *lines) const;
  4702. virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> &scatters, const QCPScatterStyle &style) const;
  4703. virtual void drawLinePlot(QCPPainter *painter, const QVector<QPointF> &lines) const;
  4704. virtual void drawImpulsePlot(QCPPainter *painter, const QVector<QPointF> &lines) const;
  4705. virtual void getOptimizedLineData(QVector<QCPGraphData> *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const;
  4706. virtual void getOptimizedScatterData(QVector<QCPGraphData> *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const;
  4707. // non-virtual methods:
  4708. void getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const;
  4709. void getLines(QVector<QPointF> *lines, const QCPDataRange &dataRange) const;
  4710. void getScatters(QVector<QPointF> *scatters, const QCPDataRange &dataRange) const;
  4711. QVector<QPointF> dataToLines(const QVector<QCPGraphData> &data) const;
  4712. QVector<QPointF> dataToStepLeftLines(const QVector<QCPGraphData> &data) const;
  4713. QVector<QPointF> dataToStepRightLines(const QVector<QCPGraphData> &data) const;
  4714. QVector<QPointF> dataToStepCenterLines(const QVector<QCPGraphData> &data) const;
  4715. QVector<QPointF> dataToImpulseLines(const QVector<QCPGraphData> &data) const;
  4716. QVector<QCPDataRange> getNonNanSegments(const QVector<QPointF> *lineData, Qt::Orientation keyOrientation) const;
  4717. QVector<QPair<QCPDataRange, QCPDataRange> > getOverlappingSegments(QVector<QCPDataRange> thisSegments, const QVector<QPointF> *thisData, QVector<QCPDataRange> otherSegments, const QVector<QPointF> *otherData) const;
  4718. bool segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const;
  4719. QPointF getFillBasePoint(QPointF matchingDataPoint) const;
  4720. const QPolygonF getFillPolygon(const QVector<QPointF> *lineData, QCPDataRange segment) const;
  4721. const QPolygonF getChannelFillPolygon(const QVector<QPointF> *thisData, QCPDataRange thisSegment, const QVector<QPointF> *otherData, QCPDataRange otherSegment) const;
  4722. int findIndexBelowX(const QVector<QPointF> *data, double x) const;
  4723. int findIndexAboveX(const QVector<QPointF> *data, double x) const;
  4724. int findIndexBelowY(const QVector<QPointF> *data, double y) const;
  4725. int findIndexAboveY(const QVector<QPointF> *data, double y) const;
  4726. double pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const;
  4727. friend class QCustomPlot;
  4728. friend class QCPLegend;
  4729. };
  4730. Q_DECLARE_METATYPE(QCPGraph::LineStyle)
  4731. /* end of 'src/plottables/plottable-graph.h' */
  4732. /* including file 'src/plottables/plottable-curve.h' */
  4733. /* modified 2022-11-06T12:45:56, size 7434 */
  4734. class QCP_LIB_DECL QCPCurveData
  4735. {
  4736. public:
  4737. QCPCurveData();
  4738. QCPCurveData(double t, double key, double value);
  4739. inline double sortKey() const { return t; }
  4740. inline static QCPCurveData fromSortKey(double sortKey) { return QCPCurveData(sortKey, 0, 0); }
  4741. inline static bool sortKeyIsMainKey() { return false; }
  4742. inline double mainKey() const { return key; }
  4743. inline double mainValue() const { return value; }
  4744. inline QCPRange valueRange() const { return QCPRange(value, value); }
  4745. double t, key, value;
  4746. };
  4747. Q_DECLARE_TYPEINFO(QCPCurveData, Q_PRIMITIVE_TYPE);
  4748. /*! \typedef QCPCurveDataContainer
  4749. Container for storing \ref QCPCurveData points. The data is stored sorted by \a t, so the \a
  4750. sortKey() (returning \a t) is different from \a mainKey() (returning \a key).
  4751. This template instantiation is the container in which QCPCurve holds its data. For details about
  4752. the generic container, see the documentation of the class template \ref QCPDataContainer.
  4753. \see QCPCurveData, QCPCurve::setData
  4754. */
  4755. typedef QCPDataContainer<QCPCurveData> QCPCurveDataContainer;
  4756. class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable1D<QCPCurveData>
  4757. {
  4758. Q_OBJECT
  4759. /// \cond INCLUDE_QPROPERTIES
  4760. Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
  4761. Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip)
  4762. Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
  4763. /// \endcond
  4764. public:
  4765. /*!
  4766. Defines how the curve's line is represented visually in the plot. The line is drawn with the
  4767. current pen of the curve (\ref setPen).
  4768. \see setLineStyle
  4769. */
  4770. enum LineStyle { lsNone ///< No line is drawn between data points (e.g. only scatters)
  4771. ,lsLine ///< Data points are connected with a straight line
  4772. };
  4773. Q_ENUMS(LineStyle)
  4774. explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis);
  4775. virtual ~QCPCurve() Q_DECL_OVERRIDE;
  4776. // getters:
  4777. QSharedPointer<QCPCurveDataContainer> data() const { return mDataContainer; }
  4778. QCPScatterStyle scatterStyle() const { return mScatterStyle; }
  4779. int scatterSkip() const { return mScatterSkip; }
  4780. LineStyle lineStyle() const { return mLineStyle; }
  4781. // setters:
  4782. void setData(QSharedPointer<QCPCurveDataContainer> data);
  4783. void setData(const QVector<double> &t, const QVector<double> &keys, const QVector<double> &values, bool alreadySorted=false);
  4784. void setData(const QVector<double> &keys, const QVector<double> &values);
  4785. void setScatterStyle(const QCPScatterStyle &style);
  4786. void setScatterSkip(int skip);
  4787. void setLineStyle(LineStyle style);
  4788. // non-property methods:
  4789. void addData(const QVector<double> &t, const QVector<double> &keys, const QVector<double> &values, bool alreadySorted=false);
  4790. void addData(const QVector<double> &keys, const QVector<double> &values);
  4791. void addData(double t, double key, double value);
  4792. void addData(double key, double value);
  4793. // reimplemented virtual methods:
  4794. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  4795. virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE;
  4796. virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE;
  4797. protected:
  4798. // property members:
  4799. QCPScatterStyle mScatterStyle;
  4800. int mScatterSkip;
  4801. LineStyle mLineStyle;
  4802. // reimplemented virtual methods:
  4803. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  4804. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE;
  4805. // introduced virtual methods:
  4806. virtual void drawCurveLine(QCPPainter *painter, const QVector<QPointF> &lines) const;
  4807. virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> &points, const QCPScatterStyle &style) const;
  4808. // non-virtual methods:
  4809. void getCurveLines(QVector<QPointF> *lines, const QCPDataRange &dataRange, double penWidth) const;
  4810. void getScatters(QVector<QPointF> *scatters, const QCPDataRange &dataRange, double scatterWidth) const;
  4811. int getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const;
  4812. QPointF getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const;
  4813. QVector<QPointF> getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const;
  4814. bool mayTraverse(int prevRegion, int currentRegion) const;
  4815. bool getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const;
  4816. void getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector<QPointF> &beforeTraverse, QVector<QPointF> &afterTraverse) const;
  4817. double pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const;
  4818. friend class QCustomPlot;
  4819. friend class QCPLegend;
  4820. };
  4821. Q_DECLARE_METATYPE(QCPCurve::LineStyle)
  4822. /* end of 'src/plottables/plottable-curve.h' */
  4823. /* including file 'src/plottables/plottable-bars.h' */
  4824. /* modified 2022-11-06T12:45:56, size 8955 */
  4825. class QCP_LIB_DECL QCPBarsGroup : public QObject
  4826. {
  4827. Q_OBJECT
  4828. /// \cond INCLUDE_QPROPERTIES
  4829. Q_PROPERTY(SpacingType spacingType READ spacingType WRITE setSpacingType)
  4830. Q_PROPERTY(double spacing READ spacing WRITE setSpacing)
  4831. /// \endcond
  4832. public:
  4833. /*!
  4834. Defines the ways the spacing between bars in the group can be specified. Thus it defines what
  4835. the number passed to \ref setSpacing actually means.
  4836. \see setSpacingType, setSpacing
  4837. */
  4838. enum SpacingType { stAbsolute ///< Bar spacing is in absolute pixels
  4839. ,stAxisRectRatio ///< Bar spacing is given by a fraction of the axis rect size
  4840. ,stPlotCoords ///< Bar spacing is in key coordinates and thus scales with the key axis range
  4841. };
  4842. Q_ENUMS(SpacingType)
  4843. explicit QCPBarsGroup(QCustomPlot *parentPlot);
  4844. virtual ~QCPBarsGroup();
  4845. // getters:
  4846. SpacingType spacingType() const { return mSpacingType; }
  4847. double spacing() const { return mSpacing; }
  4848. // setters:
  4849. void setSpacingType(SpacingType spacingType);
  4850. void setSpacing(double spacing);
  4851. // non-virtual methods:
  4852. QList<QCPBars*> bars() const { return mBars; }
  4853. QCPBars* bars(int index) const;
  4854. int size() const { return mBars.size(); }
  4855. bool isEmpty() const { return mBars.isEmpty(); }
  4856. void clear();
  4857. bool contains(QCPBars *bars) const { return mBars.contains(bars); }
  4858. void append(QCPBars *bars);
  4859. void insert(int i, QCPBars *bars);
  4860. void remove(QCPBars *bars);
  4861. protected:
  4862. // non-property members:
  4863. QCustomPlot *mParentPlot;
  4864. SpacingType mSpacingType;
  4865. double mSpacing;
  4866. QList<QCPBars*> mBars;
  4867. // non-virtual methods:
  4868. void registerBars(QCPBars *bars);
  4869. void unregisterBars(QCPBars *bars);
  4870. // virtual methods:
  4871. double keyPixelOffset(const QCPBars *bars, double keyCoord);
  4872. double getPixelSpacing(const QCPBars *bars, double keyCoord);
  4873. private:
  4874. Q_DISABLE_COPY(QCPBarsGroup)
  4875. friend class QCPBars;
  4876. };
  4877. Q_DECLARE_METATYPE(QCPBarsGroup::SpacingType)
  4878. class QCP_LIB_DECL QCPBarsData
  4879. {
  4880. public:
  4881. QCPBarsData();
  4882. QCPBarsData(double key, double value);
  4883. inline double sortKey() const { return key; }
  4884. inline static QCPBarsData fromSortKey(double sortKey) { return QCPBarsData(sortKey, 0); }
  4885. inline static bool sortKeyIsMainKey() { return true; }
  4886. inline double mainKey() const { return key; }
  4887. inline double mainValue() const { return value; }
  4888. inline QCPRange valueRange() const { return QCPRange(value, value); } // note that bar base value isn't held in each QCPBarsData and thus can't/shouldn't be returned here
  4889. double key, value;
  4890. };
  4891. Q_DECLARE_TYPEINFO(QCPBarsData, Q_PRIMITIVE_TYPE);
  4892. /*! \typedef QCPBarsDataContainer
  4893. Container for storing \ref QCPBarsData points. The data is stored sorted by \a key.
  4894. This template instantiation is the container in which QCPBars holds its data. For details about
  4895. the generic container, see the documentation of the class template \ref QCPDataContainer.
  4896. \see QCPBarsData, QCPBars::setData
  4897. */
  4898. typedef QCPDataContainer<QCPBarsData> QCPBarsDataContainer;
  4899. class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable1D<QCPBarsData>
  4900. {
  4901. Q_OBJECT
  4902. /// \cond INCLUDE_QPROPERTIES
  4903. Q_PROPERTY(double width READ width WRITE setWidth)
  4904. Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType)
  4905. Q_PROPERTY(QCPBarsGroup* barsGroup READ barsGroup WRITE setBarsGroup)
  4906. Q_PROPERTY(double baseValue READ baseValue WRITE setBaseValue)
  4907. Q_PROPERTY(double stackingGap READ stackingGap WRITE setStackingGap)
  4908. Q_PROPERTY(QCPBars* barBelow READ barBelow)
  4909. Q_PROPERTY(QCPBars* barAbove READ barAbove)
  4910. /// \endcond
  4911. public:
  4912. /*!
  4913. Defines the ways the width of the bar can be specified. Thus it defines what the number passed
  4914. to \ref setWidth actually means.
  4915. \see setWidthType, setWidth
  4916. */
  4917. enum WidthType { wtAbsolute ///< Bar width is in absolute pixels
  4918. ,wtAxisRectRatio ///< Bar width is given by a fraction of the axis rect size
  4919. ,wtPlotCoords ///< Bar width is in key coordinates and thus scales with the key axis range
  4920. };
  4921. Q_ENUMS(WidthType)
  4922. explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis);
  4923. virtual ~QCPBars() Q_DECL_OVERRIDE;
  4924. // getters:
  4925. double width() const { return mWidth; }
  4926. WidthType widthType() const { return mWidthType; }
  4927. QCPBarsGroup *barsGroup() const { return mBarsGroup; }
  4928. double baseValue() const { return mBaseValue; }
  4929. double stackingGap() const { return mStackingGap; }
  4930. QCPBars *barBelow() const { return mBarBelow.data(); }
  4931. QCPBars *barAbove() const { return mBarAbove.data(); }
  4932. QSharedPointer<QCPBarsDataContainer> data() const { return mDataContainer; }
  4933. // setters:
  4934. void setData(QSharedPointer<QCPBarsDataContainer> data);
  4935. void setData(const QVector<double> &keys, const QVector<double> &values, bool alreadySorted=false);
  4936. void setWidth(double width);
  4937. void setWidthType(WidthType widthType);
  4938. void setBarsGroup(QCPBarsGroup *barsGroup);
  4939. void setBaseValue(double baseValue);
  4940. void setStackingGap(double pixels);
  4941. // non-property methods:
  4942. void addData(const QVector<double> &keys, const QVector<double> &values, bool alreadySorted=false);
  4943. void addData(double key, double value);
  4944. void moveBelow(QCPBars *bars);
  4945. void moveAbove(QCPBars *bars);
  4946. // reimplemented virtual methods:
  4947. virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE;
  4948. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  4949. virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE;
  4950. virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE;
  4951. virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE;
  4952. protected:
  4953. // property members:
  4954. double mWidth;
  4955. WidthType mWidthType;
  4956. QCPBarsGroup *mBarsGroup;
  4957. double mBaseValue;
  4958. double mStackingGap;
  4959. QPointer<QCPBars> mBarBelow, mBarAbove;
  4960. // reimplemented virtual methods:
  4961. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  4962. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE;
  4963. // non-virtual methods:
  4964. void getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const;
  4965. QRectF getBarRect(double key, double value) const;
  4966. void getPixelWidth(double key, double &lower, double &upper) const;
  4967. double getStackedBaseValue(double key, bool positive) const;
  4968. static void connectBars(QCPBars* lower, QCPBars* upper);
  4969. friend class QCustomPlot;
  4970. friend class QCPLegend;
  4971. friend class QCPBarsGroup;
  4972. };
  4973. Q_DECLARE_METATYPE(QCPBars::WidthType)
  4974. /* end of 'src/plottables/plottable-bars.h' */
  4975. /* including file 'src/plottables/plottable-statisticalbox.h' */
  4976. /* modified 2022-11-06T12:45:56, size 7522 */
  4977. class QCP_LIB_DECL QCPStatisticalBoxData
  4978. {
  4979. public:
  4980. QCPStatisticalBoxData();
  4981. QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector<double>& outliers=QVector<double>());
  4982. inline double sortKey() const { return key; }
  4983. inline static QCPStatisticalBoxData fromSortKey(double sortKey) { return QCPStatisticalBoxData(sortKey, 0, 0, 0, 0, 0); }
  4984. inline static bool sortKeyIsMainKey() { return true; }
  4985. inline double mainKey() const { return key; }
  4986. inline double mainValue() const { return median; }
  4987. inline QCPRange valueRange() const
  4988. {
  4989. QCPRange result(minimum, maximum);
  4990. for (QVector<double>::const_iterator it = outliers.constBegin(); it != outliers.constEnd(); ++it)
  4991. result.expand(*it);
  4992. return result;
  4993. }
  4994. double key, minimum, lowerQuartile, median, upperQuartile, maximum;
  4995. QVector<double> outliers;
  4996. };
  4997. Q_DECLARE_TYPEINFO(QCPStatisticalBoxData, Q_MOVABLE_TYPE);
  4998. /*! \typedef QCPStatisticalBoxDataContainer
  4999. Container for storing \ref QCPStatisticalBoxData points. The data is stored sorted by \a key.
  5000. This template instantiation is the container in which QCPStatisticalBox holds its data. For
  5001. details about the generic container, see the documentation of the class template \ref
  5002. QCPDataContainer.
  5003. \see QCPStatisticalBoxData, QCPStatisticalBox::setData
  5004. */
  5005. typedef QCPDataContainer<QCPStatisticalBoxData> QCPStatisticalBoxDataContainer;
  5006. class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable1D<QCPStatisticalBoxData>
  5007. {
  5008. Q_OBJECT
  5009. /// \cond INCLUDE_QPROPERTIES
  5010. Q_PROPERTY(double width READ width WRITE setWidth)
  5011. Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth)
  5012. Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen)
  5013. Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen)
  5014. Q_PROPERTY(bool whiskerAntialiased READ whiskerAntialiased WRITE setWhiskerAntialiased)
  5015. Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen)
  5016. Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle)
  5017. /// \endcond
  5018. public:
  5019. explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis);
  5020. // getters:
  5021. QSharedPointer<QCPStatisticalBoxDataContainer> data() const { return mDataContainer; }
  5022. double width() const { return mWidth; }
  5023. double whiskerWidth() const { return mWhiskerWidth; }
  5024. QPen whiskerPen() const { return mWhiskerPen; }
  5025. QPen whiskerBarPen() const { return mWhiskerBarPen; }
  5026. bool whiskerAntialiased() const { return mWhiskerAntialiased; }
  5027. QPen medianPen() const { return mMedianPen; }
  5028. QCPScatterStyle outlierStyle() const { return mOutlierStyle; }
  5029. // setters:
  5030. void setData(QSharedPointer<QCPStatisticalBoxDataContainer> data);
  5031. void setData(const QVector<double> &keys, const QVector<double> &minimum, const QVector<double> &lowerQuartile, const QVector<double> &median, const QVector<double> &upperQuartile, const QVector<double> &maximum, bool alreadySorted=false);
  5032. void setWidth(double width);
  5033. void setWhiskerWidth(double width);
  5034. void setWhiskerPen(const QPen &pen);
  5035. void setWhiskerBarPen(const QPen &pen);
  5036. void setWhiskerAntialiased(bool enabled);
  5037. void setMedianPen(const QPen &pen);
  5038. void setOutlierStyle(const QCPScatterStyle &style);
  5039. // non-property methods:
  5040. void addData(const QVector<double> &keys, const QVector<double> &minimum, const QVector<double> &lowerQuartile, const QVector<double> &median, const QVector<double> &upperQuartile, const QVector<double> &maximum, bool alreadySorted=false);
  5041. void addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector<double> &outliers=QVector<double>());
  5042. // reimplemented virtual methods:
  5043. virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE;
  5044. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5045. virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE;
  5046. virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE;
  5047. protected:
  5048. // property members:
  5049. double mWidth;
  5050. double mWhiskerWidth;
  5051. QPen mWhiskerPen, mWhiskerBarPen;
  5052. bool mWhiskerAntialiased;
  5053. QPen mMedianPen;
  5054. QCPScatterStyle mOutlierStyle;
  5055. // reimplemented virtual methods:
  5056. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5057. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE;
  5058. // introduced virtual methods:
  5059. virtual void drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const;
  5060. // non-virtual methods:
  5061. void getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const;
  5062. QRectF getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const;
  5063. QVector<QLineF> getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const;
  5064. QVector<QLineF> getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const;
  5065. friend class QCustomPlot;
  5066. friend class QCPLegend;
  5067. };
  5068. /* end of 'src/plottables/plottable-statisticalbox.h' */
  5069. /* including file 'src/plottables/plottable-colormap.h' */
  5070. /* modified 2022-11-06T12:45:56, size 7092 */
  5071. class QCP_LIB_DECL QCPColorMapData
  5072. {
  5073. public:
  5074. QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange);
  5075. ~QCPColorMapData();
  5076. QCPColorMapData(const QCPColorMapData &other);
  5077. QCPColorMapData &operator=(const QCPColorMapData &other);
  5078. // getters:
  5079. int keySize() const { return mKeySize; }
  5080. int valueSize() const { return mValueSize; }
  5081. QCPRange keyRange() const { return mKeyRange; }
  5082. QCPRange valueRange() const { return mValueRange; }
  5083. QCPRange dataBounds() const { return mDataBounds; }
  5084. double data(double key, double value);
  5085. double cell(int keyIndex, int valueIndex);
  5086. unsigned char alpha(int keyIndex, int valueIndex);
  5087. // setters:
  5088. void setSize(int keySize, int valueSize);
  5089. void setKeySize(int keySize);
  5090. void setValueSize(int valueSize);
  5091. void setRange(const QCPRange &keyRange, const QCPRange &valueRange);
  5092. void setKeyRange(const QCPRange &keyRange);
  5093. void setValueRange(const QCPRange &valueRange);
  5094. void setData(double key, double value, double z);
  5095. void setCell(int keyIndex, int valueIndex, double z);
  5096. void setAlpha(int keyIndex, int valueIndex, unsigned char alpha);
  5097. // non-property methods:
  5098. void recalculateDataBounds();
  5099. void clear();
  5100. void clearAlpha();
  5101. void fill(double z);
  5102. void fillAlpha(unsigned char alpha);
  5103. bool isEmpty() const { return mIsEmpty; }
  5104. void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const;
  5105. void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const;
  5106. protected:
  5107. // property members:
  5108. int mKeySize, mValueSize;
  5109. QCPRange mKeyRange, mValueRange;
  5110. bool mIsEmpty;
  5111. // non-property members:
  5112. double *mData;
  5113. unsigned char *mAlpha;
  5114. QCPRange mDataBounds;
  5115. bool mDataModified;
  5116. bool createAlpha(bool initializeOpaque=true);
  5117. friend class QCPColorMap;
  5118. };
  5119. class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable
  5120. {
  5121. Q_OBJECT
  5122. /// \cond INCLUDE_QPROPERTIES
  5123. Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
  5124. Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
  5125. Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
  5126. Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate)
  5127. Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary)
  5128. Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale)
  5129. /// \endcond
  5130. public:
  5131. explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis);
  5132. virtual ~QCPColorMap() Q_DECL_OVERRIDE;
  5133. // getters:
  5134. QCPColorMapData *data() const { return mMapData; }
  5135. QCPRange dataRange() const { return mDataRange; }
  5136. QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
  5137. bool interpolate() const { return mInterpolate; }
  5138. bool tightBoundary() const { return mTightBoundary; }
  5139. QCPColorGradient gradient() const { return mGradient; }
  5140. QCPColorScale *colorScale() const { return mColorScale.data(); }
  5141. // setters:
  5142. void setData(QCPColorMapData *data, bool copy=false);
  5143. Q_SLOT void setDataRange(const QCPRange &dataRange);
  5144. Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
  5145. Q_SLOT void setGradient(const QCPColorGradient &gradient);
  5146. void setInterpolate(bool enabled);
  5147. void setTightBoundary(bool enabled);
  5148. void setColorScale(QCPColorScale *colorScale);
  5149. // non-property methods:
  5150. void rescaleDataRange(bool recalculateDataBounds=false);
  5151. Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18));
  5152. // reimplemented virtual methods:
  5153. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5154. virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE;
  5155. virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE;
  5156. signals:
  5157. void dataRangeChanged(const QCPRange &newRange);
  5158. void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
  5159. void gradientChanged(const QCPColorGradient &newGradient);
  5160. protected:
  5161. // property members:
  5162. QCPRange mDataRange;
  5163. QCPAxis::ScaleType mDataScaleType;
  5164. QCPColorMapData *mMapData;
  5165. QCPColorGradient mGradient;
  5166. bool mInterpolate;
  5167. bool mTightBoundary;
  5168. QPointer<QCPColorScale> mColorScale;
  5169. // non-property members:
  5170. QImage mMapImage, mUndersampledMapImage;
  5171. QPixmap mLegendIcon;
  5172. bool mMapImageInvalidated;
  5173. // introduced virtual methods:
  5174. virtual void updateMapImage();
  5175. // reimplemented virtual methods:
  5176. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5177. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE;
  5178. friend class QCustomPlot;
  5179. friend class QCPLegend;
  5180. };
  5181. /* end of 'src/plottables/plottable-colormap.h' */
  5182. /* including file 'src/plottables/plottable-financial.h' */
  5183. /* modified 2022-11-06T12:45:56, size 8644 */
  5184. class QCP_LIB_DECL QCPFinancialData
  5185. {
  5186. public:
  5187. QCPFinancialData();
  5188. QCPFinancialData(double key, double open, double high, double low, double close);
  5189. inline double sortKey() const { return key; }
  5190. inline static QCPFinancialData fromSortKey(double sortKey) { return QCPFinancialData(sortKey, 0, 0, 0, 0); }
  5191. inline static bool sortKeyIsMainKey() { return true; }
  5192. inline double mainKey() const { return key; }
  5193. inline double mainValue() const { return open; }
  5194. inline QCPRange valueRange() const { return QCPRange(low, high); } // open and close must lie between low and high, so we don't need to check them
  5195. double key, open, high, low, close;
  5196. };
  5197. Q_DECLARE_TYPEINFO(QCPFinancialData, Q_PRIMITIVE_TYPE);
  5198. /*! \typedef QCPFinancialDataContainer
  5199. Container for storing \ref QCPFinancialData points. The data is stored sorted by \a key.
  5200. This template instantiation is the container in which QCPFinancial holds its data. For details
  5201. about the generic container, see the documentation of the class template \ref QCPDataContainer.
  5202. \see QCPFinancialData, QCPFinancial::setData
  5203. */
  5204. typedef QCPDataContainer<QCPFinancialData> QCPFinancialDataContainer;
  5205. class QCP_LIB_DECL QCPFinancial : public QCPAbstractPlottable1D<QCPFinancialData>
  5206. {
  5207. Q_OBJECT
  5208. /// \cond INCLUDE_QPROPERTIES
  5209. Q_PROPERTY(ChartStyle chartStyle READ chartStyle WRITE setChartStyle)
  5210. Q_PROPERTY(double width READ width WRITE setWidth)
  5211. Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType)
  5212. Q_PROPERTY(bool twoColored READ twoColored WRITE setTwoColored)
  5213. Q_PROPERTY(QBrush brushPositive READ brushPositive WRITE setBrushPositive)
  5214. Q_PROPERTY(QBrush brushNegative READ brushNegative WRITE setBrushNegative)
  5215. Q_PROPERTY(QPen penPositive READ penPositive WRITE setPenPositive)
  5216. Q_PROPERTY(QPen penNegative READ penNegative WRITE setPenNegative)
  5217. /// \endcond
  5218. public:
  5219. /*!
  5220. Defines the ways the width of the financial bar can be specified. Thus it defines what the
  5221. number passed to \ref setWidth actually means.
  5222. \see setWidthType, setWidth
  5223. */
  5224. enum WidthType { wtAbsolute ///< width is in absolute pixels
  5225. ,wtAxisRectRatio ///< width is given by a fraction of the axis rect size
  5226. ,wtPlotCoords ///< width is in key coordinates and thus scales with the key axis range
  5227. };
  5228. Q_ENUMS(WidthType)
  5229. /*!
  5230. Defines the possible representations of OHLC data in the plot.
  5231. \see setChartStyle
  5232. */
  5233. enum ChartStyle { csOhlc ///< Open-High-Low-Close bar representation
  5234. ,csCandlestick ///< Candlestick representation
  5235. };
  5236. Q_ENUMS(ChartStyle)
  5237. explicit QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis);
  5238. virtual ~QCPFinancial() Q_DECL_OVERRIDE;
  5239. // getters:
  5240. QSharedPointer<QCPFinancialDataContainer> data() const { return mDataContainer; }
  5241. ChartStyle chartStyle() const { return mChartStyle; }
  5242. double width() const { return mWidth; }
  5243. WidthType widthType() const { return mWidthType; }
  5244. bool twoColored() const { return mTwoColored; }
  5245. QBrush brushPositive() const { return mBrushPositive; }
  5246. QBrush brushNegative() const { return mBrushNegative; }
  5247. QPen penPositive() const { return mPenPositive; }
  5248. QPen penNegative() const { return mPenNegative; }
  5249. // setters:
  5250. void setData(QSharedPointer<QCPFinancialDataContainer> data);
  5251. void setData(const QVector<double> &keys, const QVector<double> &open, const QVector<double> &high, const QVector<double> &low, const QVector<double> &close, bool alreadySorted=false);
  5252. void setChartStyle(ChartStyle style);
  5253. void setWidth(double width);
  5254. void setWidthType(WidthType widthType);
  5255. void setTwoColored(bool twoColored);
  5256. void setBrushPositive(const QBrush &brush);
  5257. void setBrushNegative(const QBrush &brush);
  5258. void setPenPositive(const QPen &pen);
  5259. void setPenNegative(const QPen &pen);
  5260. // non-property methods:
  5261. void addData(const QVector<double> &keys, const QVector<double> &open, const QVector<double> &high, const QVector<double> &low, const QVector<double> &close, bool alreadySorted=false);
  5262. void addData(double key, double open, double high, double low, double close);
  5263. // reimplemented virtual methods:
  5264. virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE;
  5265. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5266. virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE;
  5267. virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE;
  5268. // static methods:
  5269. static QCPFinancialDataContainer timeSeriesToOhlc(const QVector<double> &time, const QVector<double> &value, double timeBinSize, double timeBinOffset = 0);
  5270. protected:
  5271. // property members:
  5272. ChartStyle mChartStyle;
  5273. double mWidth;
  5274. WidthType mWidthType;
  5275. bool mTwoColored;
  5276. QBrush mBrushPositive, mBrushNegative;
  5277. QPen mPenPositive, mPenNegative;
  5278. // reimplemented virtual methods:
  5279. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5280. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE;
  5281. // non-virtual methods:
  5282. void drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected);
  5283. void drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected);
  5284. double getPixelWidth(double key, double keyPixel) const;
  5285. double ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const;
  5286. double candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const;
  5287. void getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const;
  5288. QRectF selectionHitBox(QCPFinancialDataContainer::const_iterator it) const;
  5289. friend class QCustomPlot;
  5290. friend class QCPLegend;
  5291. };
  5292. Q_DECLARE_METATYPE(QCPFinancial::ChartStyle)
  5293. /* end of 'src/plottables/plottable-financial.h' */
  5294. /* including file 'src/plottables/plottable-errorbar.h' */
  5295. /* modified 2022-11-06T12:45:56, size 7749 */
  5296. class QCP_LIB_DECL QCPErrorBarsData
  5297. {
  5298. public:
  5299. QCPErrorBarsData();
  5300. explicit QCPErrorBarsData(double error);
  5301. QCPErrorBarsData(double errorMinus, double errorPlus);
  5302. double errorMinus, errorPlus;
  5303. };
  5304. Q_DECLARE_TYPEINFO(QCPErrorBarsData, Q_PRIMITIVE_TYPE);
  5305. /*! \typedef QCPErrorBarsDataContainer
  5306. Container for storing \ref QCPErrorBarsData points. It is a typedef for <tt>QVector<\ref
  5307. QCPErrorBarsData></tt>.
  5308. This is the container in which \ref QCPErrorBars holds its data. Unlike most other data
  5309. containers for plottables, it is not based on \ref QCPDataContainer. This is because the error
  5310. bars plottable is special in that it doesn't store its own key and value coordinate per error
  5311. bar. It adopts the key and value from the plottable to which the error bars shall be applied
  5312. (\ref QCPErrorBars::setDataPlottable). So the stored \ref QCPErrorBarsData doesn't need a
  5313. sortable key, but merely an index (as \c QVector provides), which maps one-to-one to the indices
  5314. of the other plottable's data.
  5315. \see QCPErrorBarsData, QCPErrorBars::setData
  5316. */
  5317. typedef QVector<QCPErrorBarsData> QCPErrorBarsDataContainer;
  5318. class QCP_LIB_DECL QCPErrorBars : public QCPAbstractPlottable, public QCPPlottableInterface1D
  5319. {
  5320. Q_OBJECT
  5321. /// \cond INCLUDE_QPROPERTIES
  5322. Q_PROPERTY(QSharedPointer<QCPErrorBarsDataContainer> data READ data WRITE setData)
  5323. Q_PROPERTY(QCPAbstractPlottable* dataPlottable READ dataPlottable WRITE setDataPlottable)
  5324. Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType)
  5325. Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth)
  5326. Q_PROPERTY(double symbolGap READ symbolGap WRITE setSymbolGap)
  5327. /// \endcond
  5328. public:
  5329. /*!
  5330. Defines in which orientation the error bars shall appear. If your data needs both error
  5331. dimensions, create two \ref QCPErrorBars with different \ref ErrorType.
  5332. \see setErrorType
  5333. */
  5334. enum ErrorType { etKeyError ///< The errors are for the key dimension (bars appear parallel to the key axis)
  5335. ,etValueError ///< The errors are for the value dimension (bars appear parallel to the value axis)
  5336. };
  5337. Q_ENUMS(ErrorType)
  5338. explicit QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis);
  5339. virtual ~QCPErrorBars() Q_DECL_OVERRIDE;
  5340. // getters:
  5341. QSharedPointer<QCPErrorBarsDataContainer> data() const { return mDataContainer; }
  5342. QCPAbstractPlottable *dataPlottable() const { return mDataPlottable.data(); }
  5343. ErrorType errorType() const { return mErrorType; }
  5344. double whiskerWidth() const { return mWhiskerWidth; }
  5345. double symbolGap() const { return mSymbolGap; }
  5346. // setters:
  5347. void setData(QSharedPointer<QCPErrorBarsDataContainer> data);
  5348. void setData(const QVector<double> &error);
  5349. void setData(const QVector<double> &errorMinus, const QVector<double> &errorPlus);
  5350. void setDataPlottable(QCPAbstractPlottable* plottable);
  5351. void setErrorType(ErrorType type);
  5352. void setWhiskerWidth(double pixels);
  5353. void setSymbolGap(double pixels);
  5354. // non-property methods:
  5355. void addData(const QVector<double> &error);
  5356. void addData(const QVector<double> &errorMinus, const QVector<double> &errorPlus);
  5357. void addData(double error);
  5358. void addData(double errorMinus, double errorPlus);
  5359. // virtual methods of 1d plottable interface:
  5360. virtual int dataCount() const Q_DECL_OVERRIDE;
  5361. virtual double dataMainKey(int index) const Q_DECL_OVERRIDE;
  5362. virtual double dataSortKey(int index) const Q_DECL_OVERRIDE;
  5363. virtual double dataMainValue(int index) const Q_DECL_OVERRIDE;
  5364. virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE;
  5365. virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE;
  5366. virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE;
  5367. virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE;
  5368. virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE;
  5369. virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE;
  5370. // reimplemented virtual methods:
  5371. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5372. virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; }
  5373. protected:
  5374. // property members:
  5375. QSharedPointer<QCPErrorBarsDataContainer> mDataContainer;
  5376. QPointer<QCPAbstractPlottable> mDataPlottable;
  5377. ErrorType mErrorType;
  5378. double mWhiskerWidth;
  5379. double mSymbolGap;
  5380. // reimplemented virtual methods:
  5381. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5382. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE;
  5383. virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE;
  5384. virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE;
  5385. // non-virtual methods:
  5386. void getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector<QLineF> &backbones, QVector<QLineF> &whiskers) const;
  5387. void getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const;
  5388. double pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const;
  5389. // helpers:
  5390. void getDataSegments(QList<QCPDataRange> &selectedSegments, QList<QCPDataRange> &unselectedSegments) const;
  5391. bool errorBarVisible(int index) const;
  5392. bool rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const;
  5393. friend class QCustomPlot;
  5394. friend class QCPLegend;
  5395. };
  5396. /* end of 'src/plottables/plottable-errorbar.h' */
  5397. /* including file 'src/items/item-straightline.h' */
  5398. /* modified 2022-11-06T12:45:56, size 3137 */
  5399. class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem
  5400. {
  5401. Q_OBJECT
  5402. /// \cond INCLUDE_QPROPERTIES
  5403. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  5404. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  5405. /// \endcond
  5406. public:
  5407. explicit QCPItemStraightLine(QCustomPlot *parentPlot);
  5408. virtual ~QCPItemStraightLine() Q_DECL_OVERRIDE;
  5409. // getters:
  5410. QPen pen() const { return mPen; }
  5411. QPen selectedPen() const { return mSelectedPen; }
  5412. // setters;
  5413. void setPen(const QPen &pen);
  5414. void setSelectedPen(const QPen &pen);
  5415. // reimplemented virtual methods:
  5416. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5417. QCPItemPosition * const point1;
  5418. QCPItemPosition * const point2;
  5419. protected:
  5420. // property members:
  5421. QPen mPen, mSelectedPen;
  5422. // reimplemented virtual methods:
  5423. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5424. // non-virtual methods:
  5425. QLineF getRectClippedStraightLine(const QCPVector2D &base, const QCPVector2D &vec, const QRect &rect) const;
  5426. QPen mainPen() const;
  5427. };
  5428. /* end of 'src/items/item-straightline.h' */
  5429. /* including file 'src/items/item-line.h' */
  5430. /* modified 2022-11-06T12:45:56, size 3429 */
  5431. class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem
  5432. {
  5433. Q_OBJECT
  5434. /// \cond INCLUDE_QPROPERTIES
  5435. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  5436. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  5437. Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
  5438. Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
  5439. /// \endcond
  5440. public:
  5441. explicit QCPItemLine(QCustomPlot *parentPlot);
  5442. virtual ~QCPItemLine() Q_DECL_OVERRIDE;
  5443. // getters:
  5444. QPen pen() const { return mPen; }
  5445. QPen selectedPen() const { return mSelectedPen; }
  5446. QCPLineEnding head() const { return mHead; }
  5447. QCPLineEnding tail() const { return mTail; }
  5448. // setters;
  5449. void setPen(const QPen &pen);
  5450. void setSelectedPen(const QPen &pen);
  5451. void setHead(const QCPLineEnding &head);
  5452. void setTail(const QCPLineEnding &tail);
  5453. // reimplemented virtual methods:
  5454. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5455. QCPItemPosition * const start;
  5456. QCPItemPosition * const end;
  5457. protected:
  5458. // property members:
  5459. QPen mPen, mSelectedPen;
  5460. QCPLineEnding mHead, mTail;
  5461. // reimplemented virtual methods:
  5462. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5463. // non-virtual methods:
  5464. QLineF getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const;
  5465. QPen mainPen() const;
  5466. };
  5467. /* end of 'src/items/item-line.h' */
  5468. /* including file 'src/items/item-curve.h' */
  5469. /* modified 2022-11-06T12:45:56, size 3401 */
  5470. class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem
  5471. {
  5472. Q_OBJECT
  5473. /// \cond INCLUDE_QPROPERTIES
  5474. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  5475. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  5476. Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
  5477. Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
  5478. /// \endcond
  5479. public:
  5480. explicit QCPItemCurve(QCustomPlot *parentPlot);
  5481. virtual ~QCPItemCurve() Q_DECL_OVERRIDE;
  5482. // getters:
  5483. QPen pen() const { return mPen; }
  5484. QPen selectedPen() const { return mSelectedPen; }
  5485. QCPLineEnding head() const { return mHead; }
  5486. QCPLineEnding tail() const { return mTail; }
  5487. // setters;
  5488. void setPen(const QPen &pen);
  5489. void setSelectedPen(const QPen &pen);
  5490. void setHead(const QCPLineEnding &head);
  5491. void setTail(const QCPLineEnding &tail);
  5492. // reimplemented virtual methods:
  5493. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5494. QCPItemPosition * const start;
  5495. QCPItemPosition * const startDir;
  5496. QCPItemPosition * const endDir;
  5497. QCPItemPosition * const end;
  5498. protected:
  5499. // property members:
  5500. QPen mPen, mSelectedPen;
  5501. QCPLineEnding mHead, mTail;
  5502. // reimplemented virtual methods:
  5503. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5504. // non-virtual methods:
  5505. QPen mainPen() const;
  5506. };
  5507. /* end of 'src/items/item-curve.h' */
  5508. /* including file 'src/items/item-rect.h' */
  5509. /* modified 2022-11-06T12:45:56, size 3710 */
  5510. class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem
  5511. {
  5512. Q_OBJECT
  5513. /// \cond INCLUDE_QPROPERTIES
  5514. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  5515. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  5516. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  5517. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  5518. /// \endcond
  5519. public:
  5520. explicit QCPItemRect(QCustomPlot *parentPlot);
  5521. virtual ~QCPItemRect() Q_DECL_OVERRIDE;
  5522. // getters:
  5523. QPen pen() const { return mPen; }
  5524. QPen selectedPen() const { return mSelectedPen; }
  5525. QBrush brush() const { return mBrush; }
  5526. QBrush selectedBrush() const { return mSelectedBrush; }
  5527. // setters;
  5528. void setPen(const QPen &pen);
  5529. void setSelectedPen(const QPen &pen);
  5530. void setBrush(const QBrush &brush);
  5531. void setSelectedBrush(const QBrush &brush);
  5532. // reimplemented virtual methods:
  5533. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5534. QCPItemPosition * const topLeft;
  5535. QCPItemPosition * const bottomRight;
  5536. QCPItemAnchor * const top;
  5537. QCPItemAnchor * const topRight;
  5538. QCPItemAnchor * const right;
  5539. QCPItemAnchor * const bottom;
  5540. QCPItemAnchor * const bottomLeft;
  5541. QCPItemAnchor * const left;
  5542. protected:
  5543. enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
  5544. // property members:
  5545. QPen mPen, mSelectedPen;
  5546. QBrush mBrush, mSelectedBrush;
  5547. // reimplemented virtual methods:
  5548. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5549. virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE;
  5550. // non-virtual methods:
  5551. QPen mainPen() const;
  5552. QBrush mainBrush() const;
  5553. };
  5554. /* end of 'src/items/item-rect.h' */
  5555. /* including file 'src/items/item-text.h' */
  5556. /* modified 2022-11-06T12:45:56, size 5576 */
  5557. class QCP_LIB_DECL QCPItemText : public QCPAbstractItem
  5558. {
  5559. Q_OBJECT
  5560. /// \cond INCLUDE_QPROPERTIES
  5561. Q_PROPERTY(QColor color READ color WRITE setColor)
  5562. Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
  5563. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  5564. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  5565. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  5566. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  5567. Q_PROPERTY(QFont font READ font WRITE setFont)
  5568. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  5569. Q_PROPERTY(QString text READ text WRITE setText)
  5570. Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment)
  5571. Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment)
  5572. Q_PROPERTY(double rotation READ rotation WRITE setRotation)
  5573. Q_PROPERTY(QMargins padding READ padding WRITE setPadding)
  5574. /// \endcond
  5575. public:
  5576. explicit QCPItemText(QCustomPlot *parentPlot);
  5577. virtual ~QCPItemText() Q_DECL_OVERRIDE;
  5578. // getters:
  5579. QColor color() const { return mColor; }
  5580. QColor selectedColor() const { return mSelectedColor; }
  5581. QPen pen() const { return mPen; }
  5582. QPen selectedPen() const { return mSelectedPen; }
  5583. QBrush brush() const { return mBrush; }
  5584. QBrush selectedBrush() const { return mSelectedBrush; }
  5585. QFont font() const { return mFont; }
  5586. QFont selectedFont() const { return mSelectedFont; }
  5587. QString text() const { return mText; }
  5588. Qt::Alignment positionAlignment() const { return mPositionAlignment; }
  5589. Qt::Alignment textAlignment() const { return mTextAlignment; }
  5590. double rotation() const { return mRotation; }
  5591. QMargins padding() const { return mPadding; }
  5592. // setters;
  5593. void setColor(const QColor &color);
  5594. void setSelectedColor(const QColor &color);
  5595. void setPen(const QPen &pen);
  5596. void setSelectedPen(const QPen &pen);
  5597. void setBrush(const QBrush &brush);
  5598. void setSelectedBrush(const QBrush &brush);
  5599. void setFont(const QFont &font);
  5600. void setSelectedFont(const QFont &font);
  5601. void setText(const QString &text);
  5602. void setPositionAlignment(Qt::Alignment alignment);
  5603. void setTextAlignment(Qt::Alignment alignment);
  5604. void setRotation(double degrees);
  5605. void setPadding(const QMargins &padding);
  5606. // reimplemented virtual methods:
  5607. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5608. QCPItemPosition * const position;
  5609. QCPItemAnchor * const topLeft;
  5610. QCPItemAnchor * const top;
  5611. QCPItemAnchor * const topRight;
  5612. QCPItemAnchor * const right;
  5613. QCPItemAnchor * const bottomRight;
  5614. QCPItemAnchor * const bottom;
  5615. QCPItemAnchor * const bottomLeft;
  5616. QCPItemAnchor * const left;
  5617. protected:
  5618. enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft};
  5619. // property members:
  5620. QColor mColor, mSelectedColor;
  5621. QPen mPen, mSelectedPen;
  5622. QBrush mBrush, mSelectedBrush;
  5623. QFont mFont, mSelectedFont;
  5624. QString mText;
  5625. Qt::Alignment mPositionAlignment;
  5626. Qt::Alignment mTextAlignment;
  5627. double mRotation;
  5628. QMargins mPadding;
  5629. // reimplemented virtual methods:
  5630. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5631. virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE;
  5632. // non-virtual methods:
  5633. QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const;
  5634. QFont mainFont() const;
  5635. QColor mainColor() const;
  5636. QPen mainPen() const;
  5637. QBrush mainBrush() const;
  5638. };
  5639. /* end of 'src/items/item-text.h' */
  5640. /* including file 'src/items/item-ellipse.h' */
  5641. /* modified 2022-11-06T12:45:56, size 3890 */
  5642. class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem
  5643. {
  5644. Q_OBJECT
  5645. /// \cond INCLUDE_QPROPERTIES
  5646. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  5647. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  5648. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  5649. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  5650. /// \endcond
  5651. public:
  5652. explicit QCPItemEllipse(QCustomPlot *parentPlot);
  5653. virtual ~QCPItemEllipse() Q_DECL_OVERRIDE;
  5654. // getters:
  5655. QPen pen() const { return mPen; }
  5656. QPen selectedPen() const { return mSelectedPen; }
  5657. QBrush brush() const { return mBrush; }
  5658. QBrush selectedBrush() const { return mSelectedBrush; }
  5659. // setters;
  5660. void setPen(const QPen &pen);
  5661. void setSelectedPen(const QPen &pen);
  5662. void setBrush(const QBrush &brush);
  5663. void setSelectedBrush(const QBrush &brush);
  5664. // reimplemented virtual methods:
  5665. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5666. QCPItemPosition * const topLeft;
  5667. QCPItemPosition * const bottomRight;
  5668. QCPItemAnchor * const topLeftRim;
  5669. QCPItemAnchor * const top;
  5670. QCPItemAnchor * const topRightRim;
  5671. QCPItemAnchor * const right;
  5672. QCPItemAnchor * const bottomRightRim;
  5673. QCPItemAnchor * const bottom;
  5674. QCPItemAnchor * const bottomLeftRim;
  5675. QCPItemAnchor * const left;
  5676. QCPItemAnchor * const center;
  5677. protected:
  5678. enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter};
  5679. // property members:
  5680. QPen mPen, mSelectedPen;
  5681. QBrush mBrush, mSelectedBrush;
  5682. // reimplemented virtual methods:
  5683. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5684. virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE;
  5685. // non-virtual methods:
  5686. QPen mainPen() const;
  5687. QBrush mainBrush() const;
  5688. };
  5689. /* end of 'src/items/item-ellipse.h' */
  5690. /* including file 'src/items/item-pixmap.h' */
  5691. /* modified 2022-11-06T12:45:56, size 4407 */
  5692. class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem
  5693. {
  5694. Q_OBJECT
  5695. /// \cond INCLUDE_QPROPERTIES
  5696. Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
  5697. Q_PROPERTY(bool scaled READ scaled WRITE setScaled)
  5698. Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode)
  5699. Q_PROPERTY(Qt::TransformationMode transformationMode READ transformationMode)
  5700. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  5701. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  5702. /// \endcond
  5703. public:
  5704. explicit QCPItemPixmap(QCustomPlot *parentPlot);
  5705. virtual ~QCPItemPixmap() Q_DECL_OVERRIDE;
  5706. // getters:
  5707. QPixmap pixmap() const { return mPixmap; }
  5708. bool scaled() const { return mScaled; }
  5709. Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; }
  5710. Qt::TransformationMode transformationMode() const { return mTransformationMode; }
  5711. QPen pen() const { return mPen; }
  5712. QPen selectedPen() const { return mSelectedPen; }
  5713. // setters;
  5714. void setPixmap(const QPixmap &pixmap);
  5715. void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio, Qt::TransformationMode transformationMode=Qt::SmoothTransformation);
  5716. void setPen(const QPen &pen);
  5717. void setSelectedPen(const QPen &pen);
  5718. // reimplemented virtual methods:
  5719. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5720. QCPItemPosition * const topLeft;
  5721. QCPItemPosition * const bottomRight;
  5722. QCPItemAnchor * const top;
  5723. QCPItemAnchor * const topRight;
  5724. QCPItemAnchor * const right;
  5725. QCPItemAnchor * const bottom;
  5726. QCPItemAnchor * const bottomLeft;
  5727. QCPItemAnchor * const left;
  5728. protected:
  5729. enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
  5730. // property members:
  5731. QPixmap mPixmap;
  5732. QPixmap mScaledPixmap;
  5733. bool mScaled;
  5734. bool mScaledPixmapInvalidated;
  5735. Qt::AspectRatioMode mAspectRatioMode;
  5736. Qt::TransformationMode mTransformationMode;
  5737. QPen mPen, mSelectedPen;
  5738. // reimplemented virtual methods:
  5739. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5740. virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE;
  5741. // non-virtual methods:
  5742. void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false);
  5743. QRect getFinalRect(bool *flippedHorz=nullptr, bool *flippedVert=nullptr) const;
  5744. QPen mainPen() const;
  5745. };
  5746. /* end of 'src/items/item-pixmap.h' */
  5747. /* including file 'src/items/item-tracer.h' */
  5748. /* modified 2022-11-06T12:45:56, size 4811 */
  5749. class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem
  5750. {
  5751. Q_OBJECT
  5752. /// \cond INCLUDE_QPROPERTIES
  5753. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  5754. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  5755. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  5756. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  5757. Q_PROPERTY(double size READ size WRITE setSize)
  5758. Q_PROPERTY(TracerStyle style READ style WRITE setStyle)
  5759. Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph)
  5760. Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey)
  5761. Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating)
  5762. /// \endcond
  5763. public:
  5764. /*!
  5765. The different visual appearances a tracer item can have. Some styles size may be controlled with \ref setSize.
  5766. \see setStyle
  5767. */
  5768. enum TracerStyle { tsNone ///< The tracer is not visible
  5769. ,tsPlus ///< A plus shaped crosshair with limited size
  5770. ,tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect
  5771. ,tsCircle ///< A circle
  5772. ,tsSquare ///< A square
  5773. };
  5774. Q_ENUMS(TracerStyle)
  5775. explicit QCPItemTracer(QCustomPlot *parentPlot);
  5776. virtual ~QCPItemTracer() Q_DECL_OVERRIDE;
  5777. // getters:
  5778. QPen pen() const { return mPen; }
  5779. QPen selectedPen() const { return mSelectedPen; }
  5780. QBrush brush() const { return mBrush; }
  5781. QBrush selectedBrush() const { return mSelectedBrush; }
  5782. double size() const { return mSize; }
  5783. TracerStyle style() const { return mStyle; }
  5784. QCPGraph *graph() const { return mGraph; }
  5785. double graphKey() const { return mGraphKey; }
  5786. bool interpolating() const { return mInterpolating; }
  5787. // setters;
  5788. void setPen(const QPen &pen);
  5789. void setSelectedPen(const QPen &pen);
  5790. void setBrush(const QBrush &brush);
  5791. void setSelectedBrush(const QBrush &brush);
  5792. void setSize(double size);
  5793. void setStyle(TracerStyle style);
  5794. void setGraph(QCPGraph *graph);
  5795. void setGraphKey(double key);
  5796. void setInterpolating(bool enabled);
  5797. // reimplemented virtual methods:
  5798. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5799. // non-virtual methods:
  5800. void updatePosition();
  5801. QCPItemPosition * const position;
  5802. protected:
  5803. // property members:
  5804. QPen mPen, mSelectedPen;
  5805. QBrush mBrush, mSelectedBrush;
  5806. double mSize;
  5807. TracerStyle mStyle;
  5808. QCPGraph *mGraph;
  5809. double mGraphKey;
  5810. bool mInterpolating;
  5811. // reimplemented virtual methods:
  5812. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5813. // non-virtual methods:
  5814. QPen mainPen() const;
  5815. QBrush mainBrush() const;
  5816. };
  5817. Q_DECLARE_METATYPE(QCPItemTracer::TracerStyle)
  5818. /* end of 'src/items/item-tracer.h' */
  5819. /* including file 'src/items/item-bracket.h' */
  5820. /* modified 2022-11-06T12:45:56, size 3991 */
  5821. class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem
  5822. {
  5823. Q_OBJECT
  5824. /// \cond INCLUDE_QPROPERTIES
  5825. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  5826. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  5827. Q_PROPERTY(double length READ length WRITE setLength)
  5828. Q_PROPERTY(BracketStyle style READ style WRITE setStyle)
  5829. /// \endcond
  5830. public:
  5831. /*!
  5832. Defines the various visual shapes of the bracket item. The appearance can be further modified
  5833. by \ref setLength and \ref setPen.
  5834. \see setStyle
  5835. */
  5836. enum BracketStyle { bsSquare ///< A brace with angled edges
  5837. ,bsRound ///< A brace with round edges
  5838. ,bsCurly ///< A curly brace
  5839. ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression
  5840. };
  5841. Q_ENUMS(BracketStyle)
  5842. explicit QCPItemBracket(QCustomPlot *parentPlot);
  5843. virtual ~QCPItemBracket() Q_DECL_OVERRIDE;
  5844. // getters:
  5845. QPen pen() const { return mPen; }
  5846. QPen selectedPen() const { return mSelectedPen; }
  5847. double length() const { return mLength; }
  5848. BracketStyle style() const { return mStyle; }
  5849. // setters;
  5850. void setPen(const QPen &pen);
  5851. void setSelectedPen(const QPen &pen);
  5852. void setLength(double length);
  5853. void setStyle(BracketStyle style);
  5854. // reimplemented virtual methods:
  5855. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE;
  5856. QCPItemPosition * const left;
  5857. QCPItemPosition * const right;
  5858. QCPItemAnchor * const center;
  5859. protected:
  5860. // property members:
  5861. enum AnchorIndex {aiCenter};
  5862. QPen mPen, mSelectedPen;
  5863. double mLength;
  5864. BracketStyle mStyle;
  5865. // reimplemented virtual methods:
  5866. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  5867. virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE;
  5868. // non-virtual methods:
  5869. QPen mainPen() const;
  5870. };
  5871. Q_DECLARE_METATYPE(QCPItemBracket::BracketStyle)
  5872. /* end of 'src/items/item-bracket.h' */
  5873. /* including file 'src/polar/radialaxis.h' */
  5874. /* modified 2022-11-06T12:45:56, size 12227 */
  5875. class QCP_LIB_DECL QCPPolarAxisRadial : public QCPLayerable
  5876. {
  5877. Q_OBJECT
  5878. /// \cond INCLUDE_QPROPERTIES
  5879. /// \endcond
  5880. public:
  5881. /*!
  5882. Defines the reference of the angle at which a radial axis is tilted (\ref setAngle).
  5883. */
  5884. enum AngleReference { arAbsolute ///< The axis tilt is given in absolute degrees. The zero is to the right and positive angles are measured counter-clockwise.
  5885. ,arAngularAxis ///< The axis tilt is measured in the angular coordinate system given by the parent angular axis.
  5886. };
  5887. Q_ENUMS(AngleReference)
  5888. /*!
  5889. Defines the scale of an axis.
  5890. \see setScaleType
  5891. */
  5892. enum ScaleType { stLinear ///< Linear scaling
  5893. ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed axis coordinates (possibly also \ref setTicker to a \ref QCPAxisTickerLog instance).
  5894. };
  5895. Q_ENUMS(ScaleType)
  5896. /*!
  5897. Defines the selectable parts of an axis.
  5898. \see setSelectableParts, setSelectedParts
  5899. */
  5900. enum SelectablePart { spNone = 0 ///< None of the selectable parts
  5901. ,spAxis = 0x001 ///< The axis backbone and tick marks
  5902. ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually)
  5903. ,spAxisLabel = 0x004 ///< The axis label
  5904. };
  5905. Q_ENUMS(SelectablePart)
  5906. Q_FLAGS(SelectableParts)
  5907. Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
  5908. enum LabelMode { lmUpright ///<
  5909. ,lmRotated ///<
  5910. };
  5911. Q_ENUMS(LabelMode)
  5912. explicit QCPPolarAxisRadial(QCPPolarAxisAngular *parent);
  5913. virtual ~QCPPolarAxisRadial();
  5914. // getters:
  5915. bool rangeDrag() const { return mRangeDrag; }
  5916. bool rangeZoom() const { return mRangeZoom; }
  5917. double rangeZoomFactor() const { return mRangeZoomFactor; }
  5918. QCPPolarAxisAngular *angularAxis() const { return mAngularAxis; }
  5919. ScaleType scaleType() const { return mScaleType; }
  5920. const QCPRange range() const { return mRange; }
  5921. bool rangeReversed() const { return mRangeReversed; }
  5922. double angle() const { return mAngle; }
  5923. AngleReference angleReference() const { return mAngleReference; }
  5924. QSharedPointer<QCPAxisTicker> ticker() const { return mTicker; }
  5925. bool ticks() const { return mTicks; }
  5926. bool tickLabels() const { return mTickLabels; }
  5927. int tickLabelPadding() const { return mLabelPainter.padding(); }
  5928. QFont tickLabelFont() const { return mTickLabelFont; }
  5929. QColor tickLabelColor() const { return mTickLabelColor; }
  5930. double tickLabelRotation() const { return mLabelPainter.rotation(); }
  5931. LabelMode tickLabelMode() const;
  5932. QString numberFormat() const;
  5933. int numberPrecision() const { return mNumberPrecision; }
  5934. QVector<double> tickVector() const { return mTickVector; }
  5935. QVector<double> subTickVector() const { return mSubTickVector; }
  5936. QVector<QString> tickVectorLabels() const { return mTickVectorLabels; }
  5937. int tickLengthIn() const;
  5938. int tickLengthOut() const;
  5939. bool subTicks() const { return mSubTicks; }
  5940. int subTickLengthIn() const;
  5941. int subTickLengthOut() const;
  5942. QPen basePen() const { return mBasePen; }
  5943. QPen tickPen() const { return mTickPen; }
  5944. QPen subTickPen() const { return mSubTickPen; }
  5945. QFont labelFont() const { return mLabelFont; }
  5946. QColor labelColor() const { return mLabelColor; }
  5947. QString label() const { return mLabel; }
  5948. int labelPadding() const;
  5949. SelectableParts selectedParts() const { return mSelectedParts; }
  5950. SelectableParts selectableParts() const { return mSelectableParts; }
  5951. QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; }
  5952. QFont selectedLabelFont() const { return mSelectedLabelFont; }
  5953. QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; }
  5954. QColor selectedLabelColor() const { return mSelectedLabelColor; }
  5955. QPen selectedBasePen() const { return mSelectedBasePen; }
  5956. QPen selectedTickPen() const { return mSelectedTickPen; }
  5957. QPen selectedSubTickPen() const { return mSelectedSubTickPen; }
  5958. // setters:
  5959. void setRangeDrag(bool enabled);
  5960. void setRangeZoom(bool enabled);
  5961. void setRangeZoomFactor(double factor);
  5962. Q_SLOT void setScaleType(QCPPolarAxisRadial::ScaleType type);
  5963. Q_SLOT void setRange(const QCPRange &range);
  5964. void setRange(double lower, double upper);
  5965. void setRange(double position, double size, Qt::AlignmentFlag alignment);
  5966. void setRangeLower(double lower);
  5967. void setRangeUpper(double upper);
  5968. void setRangeReversed(bool reversed);
  5969. void setAngle(double degrees);
  5970. void setAngleReference(AngleReference reference);
  5971. void setTicker(QSharedPointer<QCPAxisTicker> ticker);
  5972. void setTicks(bool show);
  5973. void setTickLabels(bool show);
  5974. void setTickLabelPadding(int padding);
  5975. void setTickLabelFont(const QFont &font);
  5976. void setTickLabelColor(const QColor &color);
  5977. void setTickLabelRotation(double degrees);
  5978. void setTickLabelMode(LabelMode mode);
  5979. void setNumberFormat(const QString &formatCode);
  5980. void setNumberPrecision(int precision);
  5981. void setTickLength(int inside, int outside=0);
  5982. void setTickLengthIn(int inside);
  5983. void setTickLengthOut(int outside);
  5984. void setSubTicks(bool show);
  5985. void setSubTickLength(int inside, int outside=0);
  5986. void setSubTickLengthIn(int inside);
  5987. void setSubTickLengthOut(int outside);
  5988. void setBasePen(const QPen &pen);
  5989. void setTickPen(const QPen &pen);
  5990. void setSubTickPen(const QPen &pen);
  5991. void setLabelFont(const QFont &font);
  5992. void setLabelColor(const QColor &color);
  5993. void setLabel(const QString &str);
  5994. void setLabelPadding(int padding);
  5995. void setSelectedTickLabelFont(const QFont &font);
  5996. void setSelectedLabelFont(const QFont &font);
  5997. void setSelectedTickLabelColor(const QColor &color);
  5998. void setSelectedLabelColor(const QColor &color);
  5999. void setSelectedBasePen(const QPen &pen);
  6000. void setSelectedTickPen(const QPen &pen);
  6001. void setSelectedSubTickPen(const QPen &pen);
  6002. Q_SLOT void setSelectableParts(const QCPPolarAxisRadial::SelectableParts &selectableParts);
  6003. Q_SLOT void setSelectedParts(const QCPPolarAxisRadial::SelectableParts &selectedParts);
  6004. // reimplemented virtual methods:
  6005. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE;
  6006. // non-property methods:
  6007. void moveRange(double diff);
  6008. void scaleRange(double factor);
  6009. void scaleRange(double factor, double center);
  6010. void rescale(bool onlyVisiblePlottables=false);
  6011. void pixelToCoord(QPointF pixelPos, double &angleCoord, double &radiusCoord) const;
  6012. QPointF coordToPixel(double angleCoord, double radiusCoord) const;
  6013. double coordToRadius(double coord) const;
  6014. double radiusToCoord(double radius) const;
  6015. SelectablePart getPartAt(const QPointF &pos) const;
  6016. signals:
  6017. void rangeChanged(const QCPRange &newRange);
  6018. void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange);
  6019. void scaleTypeChanged(QCPPolarAxisRadial::ScaleType scaleType);
  6020. void selectionChanged(const QCPPolarAxisRadial::SelectableParts &parts);
  6021. void selectableChanged(const QCPPolarAxisRadial::SelectableParts &parts);
  6022. protected:
  6023. // property members:
  6024. bool mRangeDrag;
  6025. bool mRangeZoom;
  6026. double mRangeZoomFactor;
  6027. // axis base:
  6028. QCPPolarAxisAngular *mAngularAxis;
  6029. double mAngle;
  6030. AngleReference mAngleReference;
  6031. SelectableParts mSelectableParts, mSelectedParts;
  6032. QPen mBasePen, mSelectedBasePen;
  6033. // axis label:
  6034. int mLabelPadding;
  6035. QString mLabel;
  6036. QFont mLabelFont, mSelectedLabelFont;
  6037. QColor mLabelColor, mSelectedLabelColor;
  6038. // tick labels:
  6039. //int mTickLabelPadding; in label painter
  6040. bool mTickLabels;
  6041. //double mTickLabelRotation; in label painter
  6042. QFont mTickLabelFont, mSelectedTickLabelFont;
  6043. QColor mTickLabelColor, mSelectedTickLabelColor;
  6044. int mNumberPrecision;
  6045. QLatin1Char mNumberFormatChar;
  6046. bool mNumberBeautifulPowers;
  6047. bool mNumberMultiplyCross;
  6048. // ticks and subticks:
  6049. bool mTicks;
  6050. bool mSubTicks;
  6051. int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut;
  6052. QPen mTickPen, mSelectedTickPen;
  6053. QPen mSubTickPen, mSelectedSubTickPen;
  6054. // scale and range:
  6055. QCPRange mRange;
  6056. bool mRangeReversed;
  6057. ScaleType mScaleType;
  6058. // non-property members:
  6059. QPointF mCenter;
  6060. double mRadius;
  6061. QSharedPointer<QCPAxisTicker> mTicker;
  6062. QVector<double> mTickVector;
  6063. QVector<QString> mTickVectorLabels;
  6064. QVector<double> mSubTickVector;
  6065. bool mDragging;
  6066. QCPRange mDragStartRange;
  6067. QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
  6068. QCPLabelPainterPrivate mLabelPainter;
  6069. // reimplemented virtual methods:
  6070. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  6071. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  6072. virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE;
  6073. // events:
  6074. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE;
  6075. virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE;
  6076. // mouse events:
  6077. virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE;
  6078. virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE;
  6079. virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE;
  6080. virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
  6081. // non-virtual methods:
  6082. void updateGeometry(const QPointF &center, double radius);
  6083. void setupTickVectors();
  6084. QPen getBasePen() const;
  6085. QPen getTickPen() const;
  6086. QPen getSubTickPen() const;
  6087. QFont getTickLabelFont() const;
  6088. QFont getLabelFont() const;
  6089. QColor getTickLabelColor() const;
  6090. QColor getLabelColor() const;
  6091. private:
  6092. Q_DISABLE_COPY(QCPPolarAxisRadial)
  6093. friend class QCustomPlot;
  6094. friend class QCPPolarAxisAngular;
  6095. };
  6096. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPolarAxisRadial::SelectableParts)
  6097. Q_DECLARE_METATYPE(QCPPolarAxisRadial::AngleReference)
  6098. Q_DECLARE_METATYPE(QCPPolarAxisRadial::ScaleType)
  6099. Q_DECLARE_METATYPE(QCPPolarAxisRadial::SelectablePart)
  6100. /* end of 'src/polar/radialaxis.h' */
  6101. /* including file 'src/polar/layoutelement-angularaxis.h' */
  6102. /* modified 2022-11-06T12:45:56, size 13461 */
  6103. class QCP_LIB_DECL QCPPolarAxisAngular : public QCPLayoutElement
  6104. {
  6105. Q_OBJECT
  6106. /// \cond INCLUDE_QPROPERTIES
  6107. /// \endcond
  6108. public:
  6109. /*!
  6110. Defines the selectable parts of an axis.
  6111. \see setSelectableParts, setSelectedParts
  6112. */
  6113. enum SelectablePart { spNone = 0 ///< None of the selectable parts
  6114. ,spAxis = 0x001 ///< The axis backbone and tick marks
  6115. ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually)
  6116. ,spAxisLabel = 0x004 ///< The axis label
  6117. };
  6118. Q_ENUMS(SelectablePart)
  6119. Q_FLAGS(SelectableParts)
  6120. Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
  6121. /*!
  6122. TODO
  6123. */
  6124. enum LabelMode { lmUpright ///<
  6125. ,lmRotated ///<
  6126. };
  6127. Q_ENUMS(LabelMode)
  6128. explicit QCPPolarAxisAngular(QCustomPlot *parentPlot);
  6129. virtual ~QCPPolarAxisAngular();
  6130. // getters:
  6131. QPixmap background() const { return mBackgroundPixmap; }
  6132. QBrush backgroundBrush() const { return mBackgroundBrush; }
  6133. bool backgroundScaled() const { return mBackgroundScaled; }
  6134. Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
  6135. bool rangeDrag() const { return mRangeDrag; }
  6136. bool rangeZoom() const { return mRangeZoom; }
  6137. double rangeZoomFactor() const { return mRangeZoomFactor; }
  6138. const QCPRange range() const { return mRange; }
  6139. bool rangeReversed() const { return mRangeReversed; }
  6140. double angle() const { return mAngle; }
  6141. QSharedPointer<QCPAxisTicker> ticker() const { return mTicker; }
  6142. bool ticks() const { return mTicks; }
  6143. bool tickLabels() const { return mTickLabels; }
  6144. int tickLabelPadding() const { return mLabelPainter.padding(); }
  6145. QFont tickLabelFont() const { return mTickLabelFont; }
  6146. QColor tickLabelColor() const { return mTickLabelColor; }
  6147. double tickLabelRotation() const { return mLabelPainter.rotation(); }
  6148. LabelMode tickLabelMode() const;
  6149. QString numberFormat() const;
  6150. int numberPrecision() const { return mNumberPrecision; }
  6151. QVector<double> tickVector() const { return mTickVector; }
  6152. QVector<QString> tickVectorLabels() const { return mTickVectorLabels; }
  6153. int tickLengthIn() const { return mTickLengthIn; }
  6154. int tickLengthOut() const { return mTickLengthOut; }
  6155. bool subTicks() const { return mSubTicks; }
  6156. int subTickLengthIn() const { return mSubTickLengthIn; }
  6157. int subTickLengthOut() const { return mSubTickLengthOut; }
  6158. QPen basePen() const { return mBasePen; }
  6159. QPen tickPen() const { return mTickPen; }
  6160. QPen subTickPen() const { return mSubTickPen; }
  6161. QFont labelFont() const { return mLabelFont; }
  6162. QColor labelColor() const { return mLabelColor; }
  6163. QString label() const { return mLabel; }
  6164. int labelPadding() const { return mLabelPadding; }
  6165. SelectableParts selectedParts() const { return mSelectedParts; }
  6166. SelectableParts selectableParts() const { return mSelectableParts; }
  6167. QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; }
  6168. QFont selectedLabelFont() const { return mSelectedLabelFont; }
  6169. QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; }
  6170. QColor selectedLabelColor() const { return mSelectedLabelColor; }
  6171. QPen selectedBasePen() const { return mSelectedBasePen; }
  6172. QPen selectedTickPen() const { return mSelectedTickPen; }
  6173. QPen selectedSubTickPen() const { return mSelectedSubTickPen; }
  6174. QCPPolarGrid *grid() const { return mGrid; }
  6175. // setters:
  6176. void setBackground(const QPixmap &pm);
  6177. void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
  6178. void setBackground(const QBrush &brush);
  6179. void setBackgroundScaled(bool scaled);
  6180. void setBackgroundScaledMode(Qt::AspectRatioMode mode);
  6181. void setRangeDrag(bool enabled);
  6182. void setRangeZoom(bool enabled);
  6183. void setRangeZoomFactor(double factor);
  6184. Q_SLOT void setRange(const QCPRange &range);
  6185. void setRange(double lower, double upper);
  6186. void setRange(double position, double size, Qt::AlignmentFlag alignment);
  6187. void setRangeLower(double lower);
  6188. void setRangeUpper(double upper);
  6189. void setRangeReversed(bool reversed);
  6190. void setAngle(double degrees);
  6191. void setTicker(QSharedPointer<QCPAxisTicker> ticker);
  6192. void setTicks(bool show);
  6193. void setTickLabels(bool show);
  6194. void setTickLabelPadding(int padding);
  6195. void setTickLabelFont(const QFont &font);
  6196. void setTickLabelColor(const QColor &color);
  6197. void setTickLabelRotation(double degrees);
  6198. void setTickLabelMode(LabelMode mode);
  6199. void setNumberFormat(const QString &formatCode);
  6200. void setNumberPrecision(int precision);
  6201. void setTickLength(int inside, int outside=0);
  6202. void setTickLengthIn(int inside);
  6203. void setTickLengthOut(int outside);
  6204. void setSubTicks(bool show);
  6205. void setSubTickLength(int inside, int outside=0);
  6206. void setSubTickLengthIn(int inside);
  6207. void setSubTickLengthOut(int outside);
  6208. void setBasePen(const QPen &pen);
  6209. void setTickPen(const QPen &pen);
  6210. void setSubTickPen(const QPen &pen);
  6211. void setLabelFont(const QFont &font);
  6212. void setLabelColor(const QColor &color);
  6213. void setLabel(const QString &str);
  6214. void setLabelPadding(int padding);
  6215. void setLabelPosition(Qt::AlignmentFlag position);
  6216. void setSelectedTickLabelFont(const QFont &font);
  6217. void setSelectedLabelFont(const QFont &font);
  6218. void setSelectedTickLabelColor(const QColor &color);
  6219. void setSelectedLabelColor(const QColor &color);
  6220. void setSelectedBasePen(const QPen &pen);
  6221. void setSelectedTickPen(const QPen &pen);
  6222. void setSelectedSubTickPen(const QPen &pen);
  6223. Q_SLOT void setSelectableParts(const QCPPolarAxisAngular::SelectableParts &selectableParts);
  6224. Q_SLOT void setSelectedParts(const QCPPolarAxisAngular::SelectableParts &selectedParts);
  6225. // reimplemented virtual methods:
  6226. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE;
  6227. virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE;
  6228. virtual QList<QCPLayoutElement*> elements(bool recursive) const Q_DECL_OVERRIDE;
  6229. // non-property methods:
  6230. bool removeGraph(QCPPolarGraph *graph);
  6231. int radialAxisCount() const;
  6232. QCPPolarAxisRadial *radialAxis(int index=0) const;
  6233. QList<QCPPolarAxisRadial*> radialAxes() const;
  6234. QCPPolarAxisRadial *addRadialAxis(QCPPolarAxisRadial *axis=0);
  6235. bool removeRadialAxis(QCPPolarAxisRadial *axis);
  6236. QCPLayoutInset *insetLayout() const { return mInsetLayout; }
  6237. QRegion exactClipRegion() const;
  6238. void moveRange(double diff);
  6239. void scaleRange(double factor);
  6240. void scaleRange(double factor, double center);
  6241. void rescale(bool onlyVisiblePlottables=false);
  6242. double coordToAngleRad(double coord) const { return mAngleRad+(coord-mRange.lower)/mRange.size()*(mRangeReversed ? -2.0*M_PI : 2.0*M_PI); } // mention in doc that return doesn't wrap
  6243. double angleRadToCoord(double angleRad) const { return mRange.lower+(angleRad-mAngleRad)/(mRangeReversed ? -2.0*M_PI : 2.0*M_PI)*mRange.size(); }
  6244. void pixelToCoord(QPointF pixelPos, double &angleCoord, double &radiusCoord) const;
  6245. QPointF coordToPixel(double angleCoord, double radiusCoord) const;
  6246. SelectablePart getPartAt(const QPointF &pos) const;
  6247. // read-only interface imitating a QRect:
  6248. int left() const { return mRect.left(); }
  6249. int right() const { return mRect.right(); }
  6250. int top() const { return mRect.top(); }
  6251. int bottom() const { return mRect.bottom(); }
  6252. int width() const { return mRect.width(); }
  6253. int height() const { return mRect.height(); }
  6254. QSize size() const { return mRect.size(); }
  6255. QPoint topLeft() const { return mRect.topLeft(); }
  6256. QPoint topRight() const { return mRect.topRight(); }
  6257. QPoint bottomLeft() const { return mRect.bottomLeft(); }
  6258. QPoint bottomRight() const { return mRect.bottomRight(); }
  6259. QPointF center() const { return mCenter; }
  6260. double radius() const { return mRadius; }
  6261. signals:
  6262. void rangeChanged(const QCPRange &newRange);
  6263. void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange);
  6264. void selectionChanged(const QCPPolarAxisAngular::SelectableParts &parts);
  6265. void selectableChanged(const QCPPolarAxisAngular::SelectableParts &parts);
  6266. protected:
  6267. // property members:
  6268. QBrush mBackgroundBrush;
  6269. QPixmap mBackgroundPixmap;
  6270. QPixmap mScaledBackgroundPixmap;
  6271. bool mBackgroundScaled;
  6272. Qt::AspectRatioMode mBackgroundScaledMode;
  6273. QCPLayoutInset *mInsetLayout;
  6274. bool mRangeDrag;
  6275. bool mRangeZoom;
  6276. double mRangeZoomFactor;
  6277. // axis base:
  6278. double mAngle, mAngleRad;
  6279. SelectableParts mSelectableParts, mSelectedParts;
  6280. QPen mBasePen, mSelectedBasePen;
  6281. // axis label:
  6282. int mLabelPadding;
  6283. QString mLabel;
  6284. QFont mLabelFont, mSelectedLabelFont;
  6285. QColor mLabelColor, mSelectedLabelColor;
  6286. // tick labels:
  6287. //int mTickLabelPadding; in label painter
  6288. bool mTickLabels;
  6289. //double mTickLabelRotation; in label painter
  6290. QFont mTickLabelFont, mSelectedTickLabelFont;
  6291. QColor mTickLabelColor, mSelectedTickLabelColor;
  6292. int mNumberPrecision;
  6293. QLatin1Char mNumberFormatChar;
  6294. bool mNumberBeautifulPowers;
  6295. bool mNumberMultiplyCross;
  6296. // ticks and subticks:
  6297. bool mTicks;
  6298. bool mSubTicks;
  6299. int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut;
  6300. QPen mTickPen, mSelectedTickPen;
  6301. QPen mSubTickPen, mSelectedSubTickPen;
  6302. // scale and range:
  6303. QCPRange mRange;
  6304. bool mRangeReversed;
  6305. // non-property members:
  6306. QPointF mCenter;
  6307. double mRadius;
  6308. QList<QCPPolarAxisRadial*> mRadialAxes;
  6309. QCPPolarGrid *mGrid;
  6310. QList<QCPPolarGraph*> mGraphs;
  6311. QSharedPointer<QCPAxisTicker> mTicker;
  6312. QVector<double> mTickVector;
  6313. QVector<QString> mTickVectorLabels;
  6314. QVector<QPointF> mTickVectorCosSin;
  6315. QVector<double> mSubTickVector;
  6316. QVector<QPointF> mSubTickVectorCosSin;
  6317. bool mDragging;
  6318. QCPRange mDragAngularStart;
  6319. QList<QCPRange> mDragRadialStart;
  6320. QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
  6321. QCPLabelPainterPrivate mLabelPainter;
  6322. // reimplemented virtual methods:
  6323. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  6324. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  6325. virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE;
  6326. // events:
  6327. virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE;
  6328. virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE;
  6329. virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE;
  6330. virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
  6331. // non-virtual methods:
  6332. bool registerPolarGraph(QCPPolarGraph *graph);
  6333. void drawBackground(QCPPainter *painter, const QPointF &center, double radius);
  6334. void setupTickVectors();
  6335. QPen getBasePen() const;
  6336. QPen getTickPen() const;
  6337. QPen getSubTickPen() const;
  6338. QFont getTickLabelFont() const;
  6339. QFont getLabelFont() const;
  6340. QColor getTickLabelColor() const;
  6341. QColor getLabelColor() const;
  6342. private:
  6343. Q_DISABLE_COPY(QCPPolarAxisAngular)
  6344. friend class QCustomPlot;
  6345. friend class QCPPolarGrid;
  6346. friend class QCPPolarGraph;
  6347. };
  6348. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPolarAxisAngular::SelectableParts)
  6349. Q_DECLARE_METATYPE(QCPPolarAxisAngular::SelectablePart)
  6350. /* end of 'src/polar/layoutelement-angularaxis.h' */
  6351. /* including file 'src/polar/polargrid.h' */
  6352. /* modified 2022-11-06T12:45:56, size 4506 */
  6353. class QCP_LIB_DECL QCPPolarGrid :public QCPLayerable
  6354. {
  6355. Q_OBJECT
  6356. /// \cond INCLUDE_QPROPERTIES
  6357. /// \endcond
  6358. public:
  6359. /*!
  6360. TODO
  6361. */
  6362. enum GridType { gtAngular = 0x01 ///<
  6363. ,gtRadial = 0x02 ///<
  6364. ,gtAll = 0xFF ///<
  6365. ,gtNone = 0x00 ///<
  6366. };
  6367. Q_ENUMS(GridType)
  6368. Q_FLAGS(GridTypes)
  6369. Q_DECLARE_FLAGS(GridTypes, GridType)
  6370. explicit QCPPolarGrid(QCPPolarAxisAngular *parentAxis);
  6371. // getters:
  6372. QCPPolarAxisRadial *radialAxis() const { return mRadialAxis.data(); }
  6373. GridTypes type() const { return mType; }
  6374. GridTypes subGridType() const { return mSubGridType; }
  6375. bool antialiasedSubGrid() const { return mAntialiasedSubGrid; }
  6376. bool antialiasedZeroLine() const { return mAntialiasedZeroLine; }
  6377. QPen angularPen() const { return mAngularPen; }
  6378. QPen angularSubGridPen() const { return mAngularSubGridPen; }
  6379. QPen radialPen() const { return mRadialPen; }
  6380. QPen radialSubGridPen() const { return mRadialSubGridPen; }
  6381. QPen radialZeroLinePen() const { return mRadialZeroLinePen; }
  6382. // setters:
  6383. void setRadialAxis(QCPPolarAxisRadial *axis);
  6384. void setType(GridTypes type);
  6385. void setSubGridType(GridTypes type);
  6386. void setAntialiasedSubGrid(bool enabled);
  6387. void setAntialiasedZeroLine(bool enabled);
  6388. void setAngularPen(const QPen &pen);
  6389. void setAngularSubGridPen(const QPen &pen);
  6390. void setRadialPen(const QPen &pen);
  6391. void setRadialSubGridPen(const QPen &pen);
  6392. void setRadialZeroLinePen(const QPen &pen);
  6393. protected:
  6394. // property members:
  6395. GridTypes mType;
  6396. GridTypes mSubGridType;
  6397. bool mAntialiasedSubGrid, mAntialiasedZeroLine;
  6398. QPen mAngularPen, mAngularSubGridPen;
  6399. QPen mRadialPen, mRadialSubGridPen, mRadialZeroLinePen;
  6400. // non-property members:
  6401. QCPPolarAxisAngular *mParentAxis;
  6402. QPointer<QCPPolarAxisRadial> mRadialAxis;
  6403. // reimplemented virtual methods:
  6404. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
  6405. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  6406. // non-virtual methods:
  6407. void drawRadialGrid(QCPPainter *painter, const QPointF &center, const QVector<double> &coords, const QPen &pen, const QPen &zeroPen=Qt::NoPen);
  6408. void drawAngularGrid(QCPPainter *painter, const QPointF &center, double radius, const QVector<QPointF> &ticksCosSin, const QPen &pen);
  6409. private:
  6410. Q_DISABLE_COPY(QCPPolarGrid)
  6411. };
  6412. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPolarGrid::GridTypes)
  6413. Q_DECLARE_METATYPE(QCPPolarGrid::GridType)
  6414. /* end of 'src/polar/polargrid.h' */
  6415. /* including file 'src/polar/polargraph.h' */
  6416. /* modified 2022-11-06T12:45:56, size 9606 */
  6417. class QCP_LIB_DECL QCPPolarLegendItem : public QCPAbstractLegendItem
  6418. {
  6419. Q_OBJECT
  6420. public:
  6421. QCPPolarLegendItem(QCPLegend *parent, QCPPolarGraph *graph);
  6422. // getters:
  6423. QCPPolarGraph *polarGraph() { return mPolarGraph; }
  6424. protected:
  6425. // property members:
  6426. QCPPolarGraph *mPolarGraph;
  6427. // reimplemented virtual methods:
  6428. virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
  6429. virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE;
  6430. // non-virtual methods:
  6431. QPen getIconBorderPen() const;
  6432. QColor getTextColor() const;
  6433. QFont getFont() const;
  6434. };
  6435. class QCP_LIB_DECL QCPPolarGraph : public QCPLayerable
  6436. {
  6437. Q_OBJECT
  6438. /// \cond INCLUDE_QPROPERTIES
  6439. /// \endcond
  6440. public:
  6441. /*!
  6442. Defines how the graph's line is represented visually in the plot. The line is drawn with the
  6443. current pen of the graph (\ref setPen).
  6444. \see setLineStyle
  6445. */
  6446. enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented
  6447. ///< with symbols according to the scatter style, see \ref setScatterStyle)
  6448. ,lsLine ///< data points are connected by a straight line
  6449. };
  6450. Q_ENUMS(LineStyle)
  6451. QCPPolarGraph(QCPPolarAxisAngular *keyAxis, QCPPolarAxisRadial *valueAxis);
  6452. virtual ~QCPPolarGraph();
  6453. // getters:
  6454. QString name() const { return mName; }
  6455. bool antialiasedFill() const { return mAntialiasedFill; }
  6456. bool antialiasedScatters() const { return mAntialiasedScatters; }
  6457. QPen pen() const { return mPen; }
  6458. QBrush brush() const { return mBrush; }
  6459. bool periodic() const { return mPeriodic; }
  6460. QCPPolarAxisAngular *keyAxis() const { return mKeyAxis.data(); }
  6461. QCPPolarAxisRadial *valueAxis() const { return mValueAxis.data(); }
  6462. QCP::SelectionType selectable() const { return mSelectable; }
  6463. bool selected() const { return !mSelection.isEmpty(); }
  6464. QCPDataSelection selection() const { return mSelection; }
  6465. //QCPSelectionDecorator *selectionDecorator() const { return mSelectionDecorator; }
  6466. QSharedPointer<QCPGraphDataContainer> data() const { return mDataContainer; }
  6467. LineStyle lineStyle() const { return mLineStyle; }
  6468. QCPScatterStyle scatterStyle() const { return mScatterStyle; }
  6469. // setters:
  6470. void setName(const QString &name);
  6471. void setAntialiasedFill(bool enabled);
  6472. void setAntialiasedScatters(bool enabled);
  6473. void setPen(const QPen &pen);
  6474. void setBrush(const QBrush &brush);
  6475. void setPeriodic(bool enabled);
  6476. void setKeyAxis(QCPPolarAxisAngular *axis);
  6477. void setValueAxis(QCPPolarAxisRadial *axis);
  6478. Q_SLOT void setSelectable(QCP::SelectionType selectable);
  6479. Q_SLOT void setSelection(QCPDataSelection selection);
  6480. //void setSelectionDecorator(QCPSelectionDecorator *decorator);
  6481. void setData(QSharedPointer<QCPGraphDataContainer> data);
  6482. void setData(const QVector<double> &keys, const QVector<double> &values, bool alreadySorted=false);
  6483. void setLineStyle(LineStyle ls);
  6484. void setScatterStyle(const QCPScatterStyle &style);
  6485. // non-property methods:
  6486. void addData(const QVector<double> &keys, const QVector<double> &values, bool alreadySorted=false);
  6487. void addData(double key, double value);
  6488. void coordsToPixels(double key, double value, double &x, double &y) const;
  6489. const QPointF coordsToPixels(double key, double value) const;
  6490. void pixelsToCoords(double x, double y, double &key, double &value) const;
  6491. void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const;
  6492. void rescaleAxes(bool onlyEnlarge=false) const;
  6493. void rescaleKeyAxis(bool onlyEnlarge=false) const;
  6494. void rescaleValueAxis(bool onlyEnlarge=false, bool inKeyRange=false) const;
  6495. bool addToLegend(QCPLegend *legend);
  6496. bool addToLegend();
  6497. bool removeFromLegend(QCPLegend *legend) const;
  6498. bool removeFromLegend() const;
  6499. // introduced virtual methods:
  6500. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; // actually introduced in QCPLayerable as non-pure, but we want to force reimplementation for plottables
  6501. virtual QCPPlottableInterface1D *interface1D() { return 0; } // TODO: return this later, when QCPAbstractPolarPlottable is created
  6502. virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const;
  6503. virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const;
  6504. signals:
  6505. void selectionChanged(bool selected);
  6506. void selectionChanged(const QCPDataSelection &selection);
  6507. void selectableChanged(QCP::SelectionType selectable);
  6508. protected:
  6509. // property members:
  6510. QSharedPointer<QCPGraphDataContainer> mDataContainer;
  6511. LineStyle mLineStyle;
  6512. QCPScatterStyle mScatterStyle;
  6513. QString mName;
  6514. bool mAntialiasedFill, mAntialiasedScatters;
  6515. QPen mPen;
  6516. QBrush mBrush;
  6517. bool mPeriodic;
  6518. QPointer<QCPPolarAxisAngular> mKeyAxis;
  6519. QPointer<QCPPolarAxisRadial> mValueAxis;
  6520. QCP::SelectionType mSelectable;
  6521. QCPDataSelection mSelection;
  6522. //QCPSelectionDecorator *mSelectionDecorator;
  6523. // introduced virtual methods (later reimplemented TODO from QCPAbstractPolarPlottable):
  6524. virtual QRect clipRect() const;
  6525. virtual void draw(QCPPainter *painter);
  6526. virtual QCP::Interaction selectionCategory() const;
  6527. void applyDefaultAntialiasingHint(QCPPainter *painter) const;
  6528. // events:
  6529. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
  6530. virtual void deselectEvent(bool *selectionStateChanged);
  6531. // virtual drawing helpers:
  6532. virtual void drawLinePlot(QCPPainter *painter, const QVector<QPointF> &lines) const;
  6533. virtual void drawFill(QCPPainter *painter, QVector<QPointF> *lines) const;
  6534. virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> &scatters, const QCPScatterStyle &style) const;
  6535. // introduced virtual methods:
  6536. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
  6537. // non-virtual methods:
  6538. void applyFillAntialiasingHint(QCPPainter *painter) const;
  6539. void applyScattersAntialiasingHint(QCPPainter *painter) const;
  6540. double pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const;
  6541. // drawing helpers:
  6542. virtual int dataCount() const;
  6543. void getDataSegments(QList<QCPDataRange> &selectedSegments, QList<QCPDataRange> &unselectedSegments) const;
  6544. void drawPolyline(QCPPainter *painter, const QVector<QPointF> &lineData) const;
  6545. void getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const;
  6546. void getLines(QVector<QPointF> *lines, const QCPDataRange &dataRange) const;
  6547. void getScatters(QVector<QPointF> *scatters, const QCPDataRange &dataRange) const;
  6548. void getOptimizedLineData(QVector<QCPGraphData> *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const;
  6549. void getOptimizedScatterData(QVector<QCPGraphData> *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const;
  6550. QVector<QPointF> dataToLines(const QVector<QCPGraphData> &data) const;
  6551. private:
  6552. Q_DISABLE_COPY(QCPPolarGraph)
  6553. friend class QCPPolarLegendItem;
  6554. };
  6555. /* end of 'src/polar/polargraph.h' */
  6556. #endif // QCUSTOMPLOT_H