qcustomplot.h 261 KB

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