qcustomplot.h 311 KB

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