12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431 |
- /****************************************************************************
- **
- ** Copyright (C) 2016 The Qt Company Ltd.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the tools applications of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Lesser General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU Lesser
- ** General Public License version 3 as published by the Free Software
- ** Foundation and appearing in the file LICENSE.LGPL3 included in the
- ** packaging of this file. Please review the following information to
- ** ensure the GNU Lesser General Public License version 3 requirements
- ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 2.0 or (at your option) the GNU General
- ** Public license version 3 or any later version approved by the KDE Free
- ** Qt Foundation. The licenses are as published by the Free Software
- ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
- ** https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
- #include "qtpropertymanager.h"
- #include "qtpropertybrowserutils_p.h"
- #include <QtCore/QDateTime>
- #include <QtCore/QLocale>
- #include <QtCore/QMap>
- #include <QtCore/QTimer>
- #include <QtGui/QIcon>
- #include <QtCore/QMetaEnum>
- #include <QtGui/QFontDatabase>
- #include <QtWidgets/QStyleOption>
- #include <QtWidgets/QStyle>
- #include <QtWidgets/QApplication>
- #include <QtGui/QPainter>
- #include <QtWidgets/QLabel>
- #include <limits>
- #include <limits.h>
- #include <float.h>
- #if defined(Q_CC_MSVC)
- # pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
- #endif
- QT_BEGIN_NAMESPACE
- template <class PrivateData, class Value>
- static void setSimpleMinimumData(PrivateData *data, const Value &minVal)
- {
- data->minVal = minVal;
- if (data->maxVal < data->minVal)
- data->maxVal = data->minVal;
- if (data->val < data->minVal)
- data->val = data->minVal;
- }
- template <class PrivateData, class Value>
- static void setSimpleMaximumData(PrivateData *data, const Value &maxVal)
- {
- data->maxVal = maxVal;
- if (data->minVal > data->maxVal)
- data->minVal = data->maxVal;
- if (data->val > data->maxVal)
- data->val = data->maxVal;
- }
- template <class PrivateData, class Value>
- static void setSizeMinimumData(PrivateData *data, const Value &newMinVal)
- {
- data->minVal = newMinVal;
- if (data->maxVal.width() < data->minVal.width())
- data->maxVal.setWidth(data->minVal.width());
- if (data->maxVal.height() < data->minVal.height())
- data->maxVal.setHeight(data->minVal.height());
- if (data->val.width() < data->minVal.width())
- data->val.setWidth(data->minVal.width());
- if (data->val.height() < data->minVal.height())
- data->val.setHeight(data->minVal.height());
- }
- template <class PrivateData, class Value>
- static void setSizeMaximumData(PrivateData *data, const Value &newMaxVal)
- {
- data->maxVal = newMaxVal;
- if (data->minVal.width() > data->maxVal.width())
- data->minVal.setWidth(data->maxVal.width());
- if (data->minVal.height() > data->maxVal.height())
- data->minVal.setHeight(data->maxVal.height());
- if (data->val.width() > data->maxVal.width())
- data->val.setWidth(data->maxVal.width());
- if (data->val.height() > data->maxVal.height())
- data->val.setHeight(data->maxVal.height());
- }
- template <class SizeValue>
- static SizeValue qBoundSize(const SizeValue &minVal, const SizeValue &val, const SizeValue &maxVal)
- {
- SizeValue croppedVal = val;
- if (minVal.width() > val.width())
- croppedVal.setWidth(minVal.width());
- else if (maxVal.width() < val.width())
- croppedVal.setWidth(maxVal.width());
- if (minVal.height() > val.height())
- croppedVal.setHeight(minVal.height());
- else if (maxVal.height() < val.height())
- croppedVal.setHeight(maxVal.height());
- return croppedVal;
- }
- // Match the exact signature of qBound for VS 6.
- QSize qBound(QSize minVal, QSize val, QSize maxVal)
- {
- return qBoundSize(minVal, val, maxVal);
- }
- QSizeF qBound(QSizeF minVal, QSizeF val, QSizeF maxVal)
- {
- return qBoundSize(minVal, val, maxVal);
- }
- namespace {
- namespace {
- template <class Value>
- void orderBorders(Value &minVal, Value &maxVal)
- {
- if (minVal > maxVal)
- qSwap(minVal, maxVal);
- }
- template <class Value>
- static void orderSizeBorders(Value &minVal, Value &maxVal)
- {
- Value fromSize = minVal;
- Value toSize = maxVal;
- if (fromSize.width() > toSize.width()) {
- fromSize.setWidth(maxVal.width());
- toSize.setWidth(minVal.width());
- }
- if (fromSize.height() > toSize.height()) {
- fromSize.setHeight(maxVal.height());
- toSize.setHeight(minVal.height());
- }
- minVal = fromSize;
- maxVal = toSize;
- }
- void orderBorders(QSize &minVal, QSize &maxVal)
- {
- orderSizeBorders(minVal, maxVal);
- }
- void orderBorders(QSizeF &minVal, QSizeF &maxVal)
- {
- orderSizeBorders(minVal, maxVal);
- }
- }
- }
- ////////
- template <class Value, class PrivateData>
- static Value getData(const QMap<const QtProperty *, PrivateData> &propertyMap,
- Value PrivateData::*data,
- const QtProperty *property, const Value &defaultValue = Value())
- {
- const auto it = propertyMap.constFind(property);
- if (it == propertyMap.constEnd())
- return defaultValue;
- return it.value().*data;
- }
- template <class Value, class PrivateData>
- static Value getValue(const QMap<const QtProperty *, PrivateData> &propertyMap,
- const QtProperty *property, const Value &defaultValue = Value())
- {
- return getData<Value>(propertyMap, &PrivateData::val, property, defaultValue);
- }
- template <class Value, class PrivateData>
- static Value getMinimum(const QMap<const QtProperty *, PrivateData> &propertyMap,
- const QtProperty *property, const Value &defaultValue = Value())
- {
- return getData<Value>(propertyMap, &PrivateData::minVal, property, defaultValue);
- }
- template <class Value, class PrivateData>
- static Value getMaximum(const QMap<const QtProperty *, PrivateData> &propertyMap,
- const QtProperty *property, const Value &defaultValue = Value())
- {
- return getData<Value>(propertyMap, &PrivateData::maxVal, property, defaultValue);
- }
- template <class ValueChangeParameter, class Value, class PropertyManager>
- static void setSimpleValue(QMap<const QtProperty *, Value> &propertyMap,
- PropertyManager *manager,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- QtProperty *property, const Value &val)
- {
- const auto it = propertyMap.find(property);
- if (it == propertyMap.end())
- return;
- if (it.value() == val)
- return;
- it.value() = val;
- emit (manager->*propertyChangedSignal)(property);
- emit (manager->*valueChangedSignal)(property, val);
- }
- template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
- static void setValueInRange(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- QtProperty *property, const Value &val,
- void (PropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, ValueChangeParameter))
- {
- const auto it = managerPrivate->m_values.find(property);
- if (it == managerPrivate->m_values.end())
- return;
- auto &data = it.value();
- if (data.val == val)
- return;
- const Value oldVal = data.val;
- data.val = qBound(data.minVal, val, data.maxVal);
- if (data.val == oldVal)
- return;
- if (setSubPropertyValue)
- (managerPrivate->*setSubPropertyValue)(property, data.val);
- emit (manager->*propertyChangedSignal)(property);
- emit (manager->*valueChangedSignal)(property, data.val);
- }
- template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
- static void setBorderValues(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
- QtProperty *property, const Value &minVal, const Value &maxVal,
- void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
- ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
- {
- const auto it = managerPrivate->m_values.find(property);
- if (it == managerPrivate->m_values.end())
- return;
- Value fromVal = minVal;
- Value toVal = maxVal;
- orderBorders(fromVal, toVal);
- auto &data = it.value();
- if (data.minVal == fromVal && data.maxVal == toVal)
- return;
- const Value oldVal = data.val;
- data.setMinimumValue(fromVal);
- data.setMaximumValue(toVal);
- emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
- if (setSubPropertyRange)
- (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
- if (data.val == oldVal)
- return;
- emit (manager->*propertyChangedSignal)(property);
- emit (manager->*valueChangedSignal)(property, data.val);
- }
- template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
- static void setBorderValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
- QtProperty *property,
- Value (PrivateData::*getRangeVal)() const,
- void (PrivateData::*setRangeVal)(ValueChangeParameter), const Value &borderVal,
- void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
- ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
- {
- const auto it = managerPrivate->m_values.find(property);
- if (it == managerPrivate->m_values.end())
- return;
- PrivateData &data = it.value();
- if ((data.*getRangeVal)() == borderVal)
- return;
- const Value oldVal = data.val;
- (data.*setRangeVal)(borderVal);
- emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
- if (setSubPropertyRange)
- (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
- if (data.val == oldVal)
- return;
- emit (manager->*propertyChangedSignal)(property);
- emit (manager->*valueChangedSignal)(property, data.val);
- }
- template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
- static void setMinimumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
- QtProperty *property, const Value &minVal)
- {
- void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
- ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
- setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
- propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
- property, &PropertyManagerPrivate::Data::minimumValue, &PropertyManagerPrivate::Data::setMinimumValue, minVal, setSubPropertyRange);
- }
- template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
- static void setMaximumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
- QtProperty *property, const Value &maxVal)
- {
- void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
- ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
- setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
- propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
- property, &PropertyManagerPrivate::Data::maximumValue, &PropertyManagerPrivate::Data::setMaximumValue, maxVal, setSubPropertyRange);
- }
- class QtMetaEnumWrapper : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(QSizePolicy::Policy policy READ policy)
- public:
- QSizePolicy::Policy policy() const { return QSizePolicy::Ignored; }
- private:
- QtMetaEnumWrapper(QObject *parent) : QObject(parent) {}
- };
- class QtMetaEnumProvider
- {
- public:
- QtMetaEnumProvider();
- QStringList policyEnumNames() const { return m_policyEnumNames; }
- QStringList languageEnumNames() const { return m_languageEnumNames; }
- QStringList countryEnumNames(QLocale::Language language) const { return m_countryEnumNames.value(language); }
- QSizePolicy::Policy indexToSizePolicy(int index) const;
- int sizePolicyToIndex(QSizePolicy::Policy policy) const;
- void indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const;
- void localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const;
- private:
- void initLocale();
- QStringList m_policyEnumNames;
- QStringList m_languageEnumNames;
- QMap<QLocale::Language, QStringList> m_countryEnumNames;
- QMap<int, QLocale::Language> m_indexToLanguage;
- QMap<QLocale::Language, int> m_languageToIndex;
- QMap<int, QMap<int, QLocale::Country> > m_indexToCountry;
- QMap<QLocale::Language, QMap<QLocale::Country, int> > m_countryToIndex;
- QMetaEnum m_policyEnum;
- };
- static QList<QLocale::Country> sortCountries(const QList<QLocale::Country> &countries)
- {
- QMultiMap<QString, QLocale::Country> nameToCountry;
- for (QLocale::Country country : countries)
- nameToCountry.insert(QLocale::countryToString(country), country);
- return nameToCountry.values();
- }
- void QtMetaEnumProvider::initLocale()
- {
- QMultiMap<QString, QLocale::Language> nameToLanguage;
- for (int l = QLocale::C, last = QLocale::LastLanguage; l <= last; ++l) {
- const QLocale::Language language = static_cast<QLocale::Language>(l);
- QLocale locale(language);
- if (locale.language() == language)
- nameToLanguage.insert(QLocale::languageToString(language), language);
- }
- const QLocale system = QLocale::system();
- if (!nameToLanguage.contains(QLocale::languageToString(system.language())))
- nameToLanguage.insert(QLocale::languageToString(system.language()), system.language());
- const QList<QLocale::Language> languages = nameToLanguage.values();
- for (QLocale::Language language : languages) {
- QList<QLocale::Country> countries;
- countries = QLocale::countriesForLanguage(language);
- if (countries.isEmpty() && language == system.language())
- countries << system.country();
- if (!countries.isEmpty() && !m_languageToIndex.contains(language)) {
- countries = sortCountries(countries);
- int langIdx = m_languageEnumNames.count();
- m_indexToLanguage[langIdx] = language;
- m_languageToIndex[language] = langIdx;
- QStringList countryNames;
- int countryIdx = 0;
- for (QLocale::Country country : qAsConst(countries)) {
- countryNames << QLocale::countryToString(country);
- m_indexToCountry[langIdx][countryIdx] = country;
- m_countryToIndex[language][country] = countryIdx;
- ++countryIdx;
- }
- m_languageEnumNames << QLocale::languageToString(language);
- m_countryEnumNames[language] = countryNames;
- }
- }
- }
- QtMetaEnumProvider::QtMetaEnumProvider()
- {
- QMetaProperty p;
- p = QtMetaEnumWrapper::staticMetaObject.property(
- QtMetaEnumWrapper::staticMetaObject.propertyOffset() + 0);
- m_policyEnum = p.enumerator();
- const int keyCount = m_policyEnum.keyCount();
- for (int i = 0; i < keyCount; i++)
- m_policyEnumNames << QLatin1String(m_policyEnum.key(i));
- initLocale();
- }
- QSizePolicy::Policy QtMetaEnumProvider::indexToSizePolicy(int index) const
- {
- return static_cast<QSizePolicy::Policy>(m_policyEnum.value(index));
- }
- int QtMetaEnumProvider::sizePolicyToIndex(QSizePolicy::Policy policy) const
- {
- const int keyCount = m_policyEnum.keyCount();
- for (int i = 0; i < keyCount; i++)
- if (indexToSizePolicy(i) == policy)
- return i;
- return -1;
- }
- void QtMetaEnumProvider::indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const
- {
- QLocale::Language l = QLocale::C;
- QLocale::Country c = QLocale::AnyCountry;
- if (m_indexToLanguage.contains(languageIndex)) {
- l = m_indexToLanguage[languageIndex];
- if (m_indexToCountry.contains(languageIndex) && m_indexToCountry[languageIndex].contains(countryIndex))
- c = m_indexToCountry[languageIndex][countryIndex];
- }
- if (language)
- *language = l;
- if (country)
- *country = c;
- }
- void QtMetaEnumProvider::localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const
- {
- int l = -1;
- int c = -1;
- if (m_languageToIndex.contains(language)) {
- l = m_languageToIndex[language];
- if (m_countryToIndex.contains(language) && m_countryToIndex[language].contains(country))
- c = m_countryToIndex[language][country];
- }
- if (languageIndex)
- *languageIndex = l;
- if (countryIndex)
- *countryIndex = c;
- }
- Q_GLOBAL_STATIC(QtMetaEnumProvider, metaEnumProvider)
- // QtGroupPropertyManager
- /*!
- \class QtGroupPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtGroupPropertyManager provides and manages group properties.
- This class is intended to provide a grouping element without any value.
- \sa QtAbstractPropertyManager
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtGroupPropertyManager::QtGroupPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtGroupPropertyManager::~QtGroupPropertyManager()
- {
- }
- /*!
- \reimp
- */
- bool QtGroupPropertyManager::hasValue(const QtProperty *property) const
- {
- Q_UNUSED(property);
- return false;
- }
- /*!
- \reimp
- */
- void QtGroupPropertyManager::initializeProperty(QtProperty *property)
- {
- Q_UNUSED(property);
- }
- /*!
- \reimp
- */
- void QtGroupPropertyManager::uninitializeProperty(QtProperty *property)
- {
- Q_UNUSED(property);
- }
- // QtIntPropertyManager
- class QtIntPropertyManagerPrivate
- {
- QtIntPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtIntPropertyManager)
- public:
- struct Data
- {
- int val{0};
- int minVal{-INT_MAX};
- int maxVal{INT_MAX};
- int singleStep{1};
- int minimumValue() const { return minVal; }
- int maximumValue() const { return maxVal; }
- void setMinimumValue(int newMinVal) { setSimpleMinimumData(this, newMinVal); }
- void setMaximumValue(int newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*!
- \class QtIntPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtIntPropertyManager provides and manages int properties.
- An int property has a current value, and a range specifying the
- valid values. The range is defined by a minimum and a maximum
- value.
- The property's value and range can be retrieved using the value(),
- minimum() and maximum() functions, and can be set using the
- setValue(), setMinimum() and setMaximum() slots. Alternatively,
- the range can be defined in one go using the setRange() slot.
- In addition, QtIntPropertyManager provides the valueChanged() signal which
- is emitted whenever a property created by this manager changes,
- and the rangeChanged() signal which is emitted whenever such a
- property changes its range of valid values.
- \sa QtAbstractPropertyManager, QtSpinBoxFactory, QtSliderFactory, QtScrollBarFactory
- */
- /*!
- \fn void QtIntPropertyManager::valueChanged(QtProperty *property, int value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtIntPropertyManager::rangeChanged(QtProperty *property, int minimum, int maximum)
- This signal is emitted whenever a property created by this manager
- changes its range of valid values, passing a pointer to the
- \a property and the new \a minimum and \a maximum values.
- \sa setRange()
- */
- /*!
- \fn void QtIntPropertyManager::singleStepChanged(QtProperty *property, int step)
- This signal is emitted whenever a property created by this manager
- changes its single step property, passing a pointer to the
- \a property and the new \a step value
- \sa setSingleStep()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtIntPropertyManager::QtIntPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtIntPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtIntPropertyManager::~QtIntPropertyManager()
- {
- clear();
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns 0.
- \sa setValue()
- */
- int QtIntPropertyManager::value(const QtProperty *property) const
- {
- return getValue<int>(d_ptr->m_values, property, 0);
- }
- /*!
- Returns the given \a property's minimum value.
- \sa setMinimum(), maximum(), setRange()
- */
- int QtIntPropertyManager::minimum(const QtProperty *property) const
- {
- return getMinimum<int>(d_ptr->m_values, property, 0);
- }
- /*!
- Returns the given \a property's maximum value.
- \sa setMaximum(), minimum(), setRange()
- */
- int QtIntPropertyManager::maximum(const QtProperty *property) const
- {
- return getMaximum<int>(d_ptr->m_values, property, 0);
- }
- /*!
- Returns the given \a property's step value.
- The step is typically used to increment or decrement a property value while pressing an arrow key.
- \sa setSingleStep()
- */
- int QtIntPropertyManager::singleStep(const QtProperty *property) const
- {
- return getData<int>(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::singleStep, property, 0);
- }
- /*!
- \reimp
- */
- QString QtIntPropertyManager::valueText(const QtProperty *property) const
- {
- const QtIntPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return QString::number(it.value().val);
- }
- /*!
- \fn void QtIntPropertyManager::setValue(QtProperty *property, int value)
- Sets the value of the given \a property to \a value.
- If the specified \a value is not valid according to the given \a
- property's range, the \a value is adjusted to the nearest valid
- value within the range.
- \sa value(), setRange(), valueChanged()
- */
- void QtIntPropertyManager::setValue(QtProperty *property, int val)
- {
- void (QtIntPropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, int) = 0;
- setValueInRange<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr.data(),
- &QtIntPropertyManager::propertyChanged,
- &QtIntPropertyManager::valueChanged,
- property, val, setSubPropertyValue);
- }
- /*!
- Sets the minimum value for the given \a property to \a minVal.
- When setting the minimum value, the maximum and current values are
- adjusted if necessary (ensuring that the range remains valid and
- that the current value is within the range).
- \sa minimum(), setRange(), rangeChanged()
- */
- void QtIntPropertyManager::setMinimum(QtProperty *property, int minVal)
- {
- setMinimumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr.data(),
- &QtIntPropertyManager::propertyChanged,
- &QtIntPropertyManager::valueChanged,
- &QtIntPropertyManager::rangeChanged,
- property, minVal);
- }
- /*!
- Sets the maximum value for the given \a property to \a maxVal.
- When setting maximum value, the minimum and current values are
- adjusted if necessary (ensuring that the range remains valid and
- that the current value is within the range).
- \sa maximum(), setRange(), rangeChanged()
- */
- void QtIntPropertyManager::setMaximum(QtProperty *property, int maxVal)
- {
- setMaximumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr.data(),
- &QtIntPropertyManager::propertyChanged,
- &QtIntPropertyManager::valueChanged,
- &QtIntPropertyManager::rangeChanged,
- property, maxVal);
- }
- /*!
- \fn void QtIntPropertyManager::setRange(QtProperty *property, int minimum, int maximum)
- Sets the range of valid values.
- This is a convenience function defining the range of valid values
- in one go; setting the \a minimum and \a maximum values for the
- given \a property with a single function call.
- When setting a new range, the current value is adjusted if
- necessary (ensuring that the value remains within range).
- \sa setMinimum(), setMaximum(), rangeChanged()
- */
- void QtIntPropertyManager::setRange(QtProperty *property, int minVal, int maxVal)
- {
- void (QtIntPropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, int, int, int) = 0;
- setBorderValues<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr.data(),
- &QtIntPropertyManager::propertyChanged,
- &QtIntPropertyManager::valueChanged,
- &QtIntPropertyManager::rangeChanged,
- property, minVal, maxVal, setSubPropertyRange);
- }
- /*!
- Sets the step value for the given \a property to \a step.
- The step is typically used to increment or decrement a property value while pressing an arrow key.
- \sa singleStep()
- */
- void QtIntPropertyManager::setSingleStep(QtProperty *property, int step)
- {
- const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtIntPropertyManagerPrivate::Data data = it.value();
- if (step < 0)
- step = 0;
- if (data.singleStep == step)
- return;
- data.singleStep = step;
- it.value() = data;
- emit singleStepChanged(property, data.singleStep);
- }
- /*!
- \reimp
- */
- void QtIntPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtIntPropertyManagerPrivate::Data();
- }
- /*!
- \reimp
- */
- void QtIntPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtDoublePropertyManager
- class QtDoublePropertyManagerPrivate
- {
- QtDoublePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtDoublePropertyManager)
- public:
- struct Data
- {
- double val{0};
- double minVal{-DBL_MAX};
- double maxVal{DBL_MAX};
- double singleStep{1};
- int decimals{2};
- double minimumValue() const { return minVal; }
- double maximumValue() const { return maxVal; }
- void setMinimumValue(double newMinVal) { setSimpleMinimumData(this, newMinVal); }
- void setMaximumValue(double newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*!
- \class QtDoublePropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtDoublePropertyManager provides and manages double properties.
- A double property has a current value, and a range specifying the
- valid values. The range is defined by a minimum and a maximum
- value.
- The property's value and range can be retrieved using the value(),
- minimum() and maximum() functions, and can be set using the
- setValue(), setMinimum() and setMaximum() slots.
- Alternatively, the range can be defined in one go using the
- setRange() slot.
- In addition, QtDoublePropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the rangeChanged() signal which is emitted whenever
- such a property changes its range of valid values.
- \sa QtAbstractPropertyManager, QtDoubleSpinBoxFactory
- */
- /*!
- \fn void QtDoublePropertyManager::valueChanged(QtProperty *property, double value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtDoublePropertyManager::rangeChanged(QtProperty *property, double minimum, double maximum)
- This signal is emitted whenever a property created by this manager
- changes its range of valid values, passing a pointer to the
- \a property and the new \a minimum and \a maximum values
- \sa setRange()
- */
- /*!
- \fn void QtDoublePropertyManager::decimalsChanged(QtProperty *property, int prec)
- This signal is emitted whenever a property created by this manager
- changes its precision of value, passing a pointer to the
- \a property and the new \a prec value
- \sa setDecimals()
- */
- /*!
- \fn void QtDoublePropertyManager::singleStepChanged(QtProperty *property, double step)
- This signal is emitted whenever a property created by this manager
- changes its single step property, passing a pointer to the
- \a property and the new \a step value
- \sa setSingleStep()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtDoublePropertyManager::QtDoublePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtDoublePropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtDoublePropertyManager::~QtDoublePropertyManager()
- {
- clear();
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns 0.
- \sa setValue()
- */
- double QtDoublePropertyManager::value(const QtProperty *property) const
- {
- return getValue<double>(d_ptr->m_values, property, 0.0);
- }
- /*!
- Returns the given \a property's minimum value.
- \sa maximum(), setRange()
- */
- double QtDoublePropertyManager::minimum(const QtProperty *property) const
- {
- return getMinimum<double>(d_ptr->m_values, property, 0.0);
- }
- /*!
- Returns the given \a property's maximum value.
- \sa minimum(), setRange()
- */
- double QtDoublePropertyManager::maximum(const QtProperty *property) const
- {
- return getMaximum<double>(d_ptr->m_values, property, 0.0);
- }
- /*!
- Returns the given \a property's step value.
- The step is typically used to increment or decrement a property value while pressing an arrow key.
- \sa setSingleStep()
- */
- double QtDoublePropertyManager::singleStep(const QtProperty *property) const
- {
- return getData<double>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::singleStep, property, 0);
- }
- /*!
- Returns the given \a property's precision, in decimals.
- \sa setDecimals()
- */
- int QtDoublePropertyManager::decimals(const QtProperty *property) const
- {
- return getData<int>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::decimals, property, 0);
- }
- /*!
- \reimp
- */
- QString QtDoublePropertyManager::valueText(const QtProperty *property) const
- {
- const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return QString::number(it.value().val, 'f', it.value().decimals);
- }
- /*!
- \fn void QtDoublePropertyManager::setValue(QtProperty *property, double value)
- Sets the value of the given \a property to \a value.
- If the specified \a value is not valid according to the given
- \a property's range, the \a value is adjusted to the nearest valid value
- within the range.
- \sa value(), setRange(), valueChanged()
- */
- void QtDoublePropertyManager::setValue(QtProperty *property, double val)
- {
- void (QtDoublePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, double) = 0;
- setValueInRange<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr.data(),
- &QtDoublePropertyManager::propertyChanged,
- &QtDoublePropertyManager::valueChanged,
- property, val, setSubPropertyValue);
- }
- /*!
- Sets the step value for the given \a property to \a step.
- The step is typically used to increment or decrement a property value while pressing an arrow key.
- \sa singleStep()
- */
- void QtDoublePropertyManager::setSingleStep(QtProperty *property, double step)
- {
- const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtDoublePropertyManagerPrivate::Data data = it.value();
- if (step < 0)
- step = 0;
- if (data.singleStep == step)
- return;
- data.singleStep = step;
- it.value() = data;
- emit singleStepChanged(property, data.singleStep);
- }
- /*!
- \fn void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
- Sets the precision of the given \a property to \a prec.
- The valid decimal range is 0-13. The default is 2.
- \sa decimals()
- */
- void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
- {
- const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtDoublePropertyManagerPrivate::Data data = it.value();
- if (prec > 13)
- prec = 13;
- else if (prec < 0)
- prec = 0;
- if (data.decimals == prec)
- return;
- data.decimals = prec;
- it.value() = data;
- emit decimalsChanged(property, data.decimals);
- }
- /*!
- Sets the minimum value for the given \a property to \a minVal.
- When setting the minimum value, the maximum and current values are
- adjusted if necessary (ensuring that the range remains valid and
- that the current value is within in the range).
- \sa minimum(), setRange(), rangeChanged()
- */
- void QtDoublePropertyManager::setMinimum(QtProperty *property, double minVal)
- {
- setMinimumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr.data(),
- &QtDoublePropertyManager::propertyChanged,
- &QtDoublePropertyManager::valueChanged,
- &QtDoublePropertyManager::rangeChanged,
- property, minVal);
- }
- /*!
- Sets the maximum value for the given \a property to \a maxVal.
- When setting the maximum value, the minimum and current values are
- adjusted if necessary (ensuring that the range remains valid and
- that the current value is within in the range).
- \sa maximum(), setRange(), rangeChanged()
- */
- void QtDoublePropertyManager::setMaximum(QtProperty *property, double maxVal)
- {
- setMaximumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr.data(),
- &QtDoublePropertyManager::propertyChanged,
- &QtDoublePropertyManager::valueChanged,
- &QtDoublePropertyManager::rangeChanged,
- property, maxVal);
- }
- /*!
- \fn void QtDoublePropertyManager::setRange(QtProperty *property, double minimum, double maximum)
- Sets the range of valid values.
- This is a convenience function defining the range of valid values
- in one go; setting the \a minimum and \a maximum values for the
- given \a property with a single function call.
- When setting a new range, the current value is adjusted if
- necessary (ensuring that the value remains within range).
- \sa setMinimum(), setMaximum(), rangeChanged()
- */
- void QtDoublePropertyManager::setRange(QtProperty *property, double minVal, double maxVal)
- {
- void (QtDoublePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, double, double, double) = 0;
- setBorderValues<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr.data(),
- &QtDoublePropertyManager::propertyChanged,
- &QtDoublePropertyManager::valueChanged,
- &QtDoublePropertyManager::rangeChanged,
- property, minVal, maxVal, setSubPropertyRange);
- }
- /*!
- \reimp
- */
- void QtDoublePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtDoublePropertyManagerPrivate::Data();
- }
- /*!
- \reimp
- */
- void QtDoublePropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtStringPropertyManager
- class QtStringPropertyManagerPrivate
- {
- QtStringPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtStringPropertyManager)
- public:
- struct Data
- {
- Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard)
- {
- }
- QString val;
- QRegExp regExp;
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- QMap<const QtProperty *, Data> m_values;
- };
- /*!
- \class QtStringPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtStringPropertyManager provides and manages QString properties.
- A string property's value can be retrieved using the value()
- function, and set using the setValue() slot.
- The current value can be checked against a regular expression. To
- set the regular expression use the setRegExp() slot, use the
- regExp() function to retrieve the currently set expression.
- In addition, QtStringPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the regExpChanged() signal which is emitted whenever
- such a property changes its currently set regular expression.
- \sa QtAbstractPropertyManager, QtLineEditFactory
- */
- /*!
- \fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegExp ®Exp)
- This signal is emitted whenever a property created by this manager
- changes its currenlty set regular expression, passing a pointer to
- the \a property and the new \a regExp as parameters.
- \sa setRegExp()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtStringPropertyManager::QtStringPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtStringPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtStringPropertyManager::~QtStringPropertyManager()
- {
- clear();
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns an empty string.
- \sa setValue()
- */
- QString QtStringPropertyManager::value(const QtProperty *property) const
- {
- return getValue<QString>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's currently set regular expression.
- If the given \a property is not managed by this manager, this
- function returns an empty expression.
- \sa setRegExp()
- */
- QRegExp QtStringPropertyManager::regExp(const QtProperty *property) const
- {
- return getData<QRegExp>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegExp());
- }
- /*!
- \reimp
- */
- QString QtStringPropertyManager::valueText(const QtProperty *property) const
- {
- const QtStringPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return it.value().val;
- }
- /*!
- \fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value)
- Sets the value of the given \a property to \a value.
- If the specified \a value doesn't match the given \a property's
- regular expression, this function does nothing.
- \sa value(), setRegExp(), valueChanged()
- */
- void QtStringPropertyManager::setValue(QtProperty *property, const QString &val)
- {
- const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtStringPropertyManagerPrivate::Data data = it.value();
- if (data.val == val)
- return;
- if (data.regExp.isValid() && !data.regExp.exactMatch(val))
- return;
- data.val = val;
- it.value() = data;
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the regular expression of the given \a property to \a regExp.
- \sa regExp(), setValue(), regExpChanged()
- */
- void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegExp ®Exp)
- {
- const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtStringPropertyManagerPrivate::Data data = it.value() ;
- if (data.regExp == regExp)
- return;
- data.regExp = regExp;
- it.value() = data;
- emit regExpChanged(property, data.regExp);
- }
- /*!
- \reimp
- */
- void QtStringPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtStringPropertyManagerPrivate::Data();
- }
- /*!
- \reimp
- */
- void QtStringPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtBoolPropertyManager
- // Return an icon containing a check box indicator
- static QIcon drawCheckBox(bool value)
- {
- QStyleOptionButton opt;
- opt.state |= value ? QStyle::State_On : QStyle::State_Off;
- opt.state |= QStyle::State_Enabled;
- const QStyle *style = QApplication::style();
- // Figure out size of an indicator and make sure it is not scaled down in a list view item
- // by making the pixmap as big as a list view icon and centering the indicator in it.
- // (if it is smaller, it can't be helped)
- const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt);
- const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt);
- const int listViewIconSize = indicatorWidth;
- const int pixmapWidth = indicatorWidth;
- const int pixmapHeight = qMax(indicatorHeight, listViewIconSize);
- opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight);
- QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight);
- pixmap.fill(Qt::transparent);
- {
- // Center?
- const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0;
- const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0;
- QPainter painter(&pixmap);
- painter.translate(xoff, yoff);
- style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
- }
- return QIcon(pixmap);
- }
- class QtBoolPropertyManagerPrivate
- {
- QtBoolPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtBoolPropertyManager)
- public:
- QtBoolPropertyManagerPrivate();
- QMap<const QtProperty *, bool> m_values;
- const QIcon m_checkedIcon;
- const QIcon m_uncheckedIcon;
- };
- QtBoolPropertyManagerPrivate::QtBoolPropertyManagerPrivate() :
- m_checkedIcon(drawCheckBox(true)),
- m_uncheckedIcon(drawCheckBox(false))
- {
- }
- /*!
- \class QtBoolPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtBoolPropertyManager class provides and manages boolean properties.
- The property's value can be retrieved using the value() function,
- and set using the setValue() slot.
- In addition, QtBoolPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager, QtCheckBoxFactory
- */
- /*!
- \fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtBoolPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtBoolPropertyManager::~QtBoolPropertyManager()
- {
- clear();
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by \e this manager, this
- function returns false.
- \sa setValue()
- */
- bool QtBoolPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, false);
- }
- /*!
- \reimp
- */
- QString QtBoolPropertyManager::valueText(const QtProperty *property) const
- {
- const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- static const QString trueText = tr("True");
- static const QString falseText = tr("False");
- return it.value() ? trueText : falseText;
- }
- /*!
- \reimp
- */
- QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const
- {
- const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QIcon();
- return it.value() ? d_ptr->m_checkedIcon : d_ptr->m_uncheckedIcon;
- }
- /*!
- \fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value)
- Sets the value of the given \a property to \a value.
- \sa value()
- */
- void QtBoolPropertyManager::setValue(QtProperty *property, bool val)
- {
- setSimpleValue<bool, bool, QtBoolPropertyManager>(d_ptr->m_values, this,
- &QtBoolPropertyManager::propertyChanged,
- &QtBoolPropertyManager::valueChanged,
- property, val);
- }
- /*!
- \reimp
- */
- void QtBoolPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = false;
- }
- /*!
- \reimp
- */
- void QtBoolPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtDatePropertyManager
- class QtDatePropertyManagerPrivate
- {
- QtDatePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtDatePropertyManager)
- public:
- explicit QtDatePropertyManagerPrivate(QtDatePropertyManager *q);
- struct Data
- {
- QDate val{QDate::currentDate()};
- QDate minVal{QDate(1752, 9, 14)};
- QDate maxVal{QDate(9999, 12, 31)};
- QDate minimumValue() const { return minVal; }
- QDate maximumValue() const { return maxVal; }
- void setMinimumValue(const QDate &newMinVal) { setSimpleMinimumData(this, newMinVal); }
- void setMaximumValue(const QDate &newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
- };
- QString m_format;
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- QMap<const QtProperty *, Data> m_values;
- };
- QtDatePropertyManagerPrivate::QtDatePropertyManagerPrivate(QtDatePropertyManager *q) :
- q_ptr(q),
- m_format(QtPropertyBrowserUtils::dateFormat())
- {
- }
- /*!
- \class QtDatePropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtDatePropertyManager provides and manages QDate properties.
- A date property has a current value, and a range specifying the
- valid dates. The range is defined by a minimum and a maximum
- value.
- The property's values can be retrieved using the minimum(),
- maximum() and value() functions, and can be set using the
- setMinimum(), setMaximum() and setValue() slots. Alternatively,
- the range can be defined in one go using the setRange() slot.
- In addition, QtDatePropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the rangeChanged() signal which is emitted whenever
- such a property changes its range of valid dates.
- \sa QtAbstractPropertyManager, QtDateEditFactory, QtDateTimePropertyManager
- */
- /*!
- \fn void QtDatePropertyManager::valueChanged(QtProperty *property, const QDate &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtDatePropertyManager::rangeChanged(QtProperty *property, const QDate &minimum, const QDate &maximum)
- This signal is emitted whenever a property created by this manager
- changes its range of valid dates, passing a pointer to the \a
- property and the new \a minimum and \a maximum dates.
- \sa setRange()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtDatePropertyManager::QtDatePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtDatePropertyManagerPrivate(this))
- {
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtDatePropertyManager::~QtDatePropertyManager()
- {
- clear();
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by \e this manager, this
- function returns an invalid date.
- \sa setValue()
- */
- QDate QtDatePropertyManager::value(const QtProperty *property) const
- {
- return getValue<QDate>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's minimum date.
- \sa maximum(), setRange()
- */
- QDate QtDatePropertyManager::minimum(const QtProperty *property) const
- {
- return getMinimum<QDate>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's maximum date.
- \sa minimum(), setRange()
- */
- QDate QtDatePropertyManager::maximum(const QtProperty *property) const
- {
- return getMaximum<QDate>(d_ptr->m_values, property);
- }
- /*!
- \reimp
- */
- QString QtDatePropertyManager::valueText(const QtProperty *property) const
- {
- const QtDatePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return it.value().val.toString(d_ptr->m_format);
- }
- /*!
- \fn void QtDatePropertyManager::setValue(QtProperty *property, const QDate &value)
- Sets the value of the given \a property to \a value.
- If the specified \a value is not a valid date according to the
- given \a property's range, the value is adjusted to the nearest
- valid value within the range.
- \sa value(), setRange(), valueChanged()
- */
- void QtDatePropertyManager::setValue(QtProperty *property, const QDate &val)
- {
- void (QtDatePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, const QDate &) = 0;
- setValueInRange<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, const QDate>(this, d_ptr.data(),
- &QtDatePropertyManager::propertyChanged,
- &QtDatePropertyManager::valueChanged,
- property, val, setSubPropertyValue);
- }
- /*!
- Sets the minimum value for the given \a property to \a minVal.
- When setting the minimum value, the maximum and current values are
- adjusted if necessary (ensuring that the range remains valid and
- that the current value is within in the range).
- \sa minimum(), setRange()
- */
- void QtDatePropertyManager::setMinimum(QtProperty *property, const QDate &minVal)
- {
- setMinimumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr.data(),
- &QtDatePropertyManager::propertyChanged,
- &QtDatePropertyManager::valueChanged,
- &QtDatePropertyManager::rangeChanged,
- property, minVal);
- }
- /*!
- Sets the maximum value for the given \a property to \a maxVal.
- When setting the maximum value, the minimum and current
- values are adjusted if necessary (ensuring that the range remains
- valid and that the current value is within in the range).
- \sa maximum(), setRange()
- */
- void QtDatePropertyManager::setMaximum(QtProperty *property, const QDate &maxVal)
- {
- setMaximumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr.data(),
- &QtDatePropertyManager::propertyChanged,
- &QtDatePropertyManager::valueChanged,
- &QtDatePropertyManager::rangeChanged,
- property, maxVal);
- }
- /*!
- \fn void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minimum, const QDate &maximum)
- Sets the range of valid dates.
- This is a convenience function defining the range of valid dates
- in one go; setting the \a minimum and \a maximum values for the
- given \a property with a single function call.
- When setting a new date range, the current value is adjusted if
- necessary (ensuring that the value remains in date range).
- \sa setMinimum(), setMaximum(), rangeChanged()
- */
- void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minVal, const QDate &maxVal)
- {
- void (QtDatePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, const QDate &,
- const QDate &, const QDate &) = 0;
- setBorderValues<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate>(this, d_ptr.data(),
- &QtDatePropertyManager::propertyChanged,
- &QtDatePropertyManager::valueChanged,
- &QtDatePropertyManager::rangeChanged,
- property, minVal, maxVal, setSubPropertyRange);
- }
- /*!
- \reimp
- */
- void QtDatePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtDatePropertyManagerPrivate::Data();
- }
- /*!
- \reimp
- */
- void QtDatePropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtTimePropertyManager
- class QtTimePropertyManagerPrivate
- {
- QtTimePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtTimePropertyManager)
- public:
- explicit QtTimePropertyManagerPrivate(QtTimePropertyManager *q);
- const QString m_format;
- typedef QMap<const QtProperty *, QTime> PropertyValueMap;
- PropertyValueMap m_values;
- };
- QtTimePropertyManagerPrivate::QtTimePropertyManagerPrivate(QtTimePropertyManager *q) :
- q_ptr(q),
- m_format(QtPropertyBrowserUtils::timeFormat())
- {
- }
- /*!
- \class QtTimePropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtTimePropertyManager provides and manages QTime properties.
- A time property's value can be retrieved using the value()
- function, and set using the setValue() slot.
- In addition, QtTimePropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager, QtTimeEditFactory
- */
- /*!
- \fn void QtTimePropertyManager::valueChanged(QtProperty *property, const QTime &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtTimePropertyManager::QtTimePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtTimePropertyManagerPrivate(this))
- {
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtTimePropertyManager::~QtTimePropertyManager()
- {
- clear();
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns an invalid time object.
- \sa setValue()
- */
- QTime QtTimePropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QTime());
- }
- /*!
- \reimp
- */
- QString QtTimePropertyManager::valueText(const QtProperty *property) const
- {
- const QtTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return it.value().toString(d_ptr->m_format);
- }
- /*!
- \fn void QtTimePropertyManager::setValue(QtProperty *property, const QTime &value)
- Sets the value of the given \a property to \a value.
- \sa value(), valueChanged()
- */
- void QtTimePropertyManager::setValue(QtProperty *property, const QTime &val)
- {
- setSimpleValue<const QTime &, QTime, QtTimePropertyManager>(d_ptr->m_values, this,
- &QtTimePropertyManager::propertyChanged,
- &QtTimePropertyManager::valueChanged,
- property, val);
- }
- /*!
- \reimp
- */
- void QtTimePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QTime::currentTime();
- }
- /*!
- \reimp
- */
- void QtTimePropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtDateTimePropertyManager
- class QtDateTimePropertyManagerPrivate
- {
- QtDateTimePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtDateTimePropertyManager)
- public:
- explicit QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q);
- const QString m_format;
- typedef QMap<const QtProperty *, QDateTime> PropertyValueMap;
- PropertyValueMap m_values;
- };
- QtDateTimePropertyManagerPrivate::QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q) :
- q_ptr(q),
- m_format(QtPropertyBrowserUtils::dateTimeFormat())
- {
- }
- /*! \class QtDateTimePropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtDateTimePropertyManager provides and manages QDateTime properties.
- A date and time property has a current value which can be
- retrieved using the value() function, and set using the setValue()
- slot. In addition, QtDateTimePropertyManager provides the
- valueChanged() signal which is emitted whenever a property created
- by this manager changes.
- \sa QtAbstractPropertyManager, QtDateTimeEditFactory, QtDatePropertyManager
- */
- /*!
- \fn void QtDateTimePropertyManager::valueChanged(QtProperty *property, const QDateTime &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtDateTimePropertyManagerPrivate(this))
- {
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtDateTimePropertyManager::~QtDateTimePropertyManager()
- {
- clear();
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an invalid QDateTime object.
- \sa setValue()
- */
- QDateTime QtDateTimePropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QDateTime());
- }
- /*!
- \reimp
- */
- QString QtDateTimePropertyManager::valueText(const QtProperty *property) const
- {
- const QtDateTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return it.value().toString(d_ptr->m_format);
- }
- /*!
- \fn void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &value)
- Sets the value of the given \a property to \a value.
- \sa value(), valueChanged()
- */
- void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &val)
- {
- setSimpleValue<const QDateTime &, QDateTime, QtDateTimePropertyManager>(d_ptr->m_values, this,
- &QtDateTimePropertyManager::propertyChanged,
- &QtDateTimePropertyManager::valueChanged,
- property, val);
- }
- /*!
- \reimp
- */
- void QtDateTimePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QDateTime::currentDateTime();
- }
- /*!
- \reimp
- */
- void QtDateTimePropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtKeySequencePropertyManager
- class QtKeySequencePropertyManagerPrivate
- {
- QtKeySequencePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtKeySequencePropertyManager)
- public:
- QString m_format;
- typedef QMap<const QtProperty *, QKeySequence> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*! \class QtKeySequencePropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtKeySequencePropertyManager provides and manages QKeySequence properties.
- A key sequence's value can be retrieved using the value()
- function, and set using the setValue() slot.
- In addition, QtKeySequencePropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager
- */
- /*!
- \fn void QtKeySequencePropertyManager::valueChanged(QtProperty *property, const QKeySequence &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtKeySequencePropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtKeySequencePropertyManager::~QtKeySequencePropertyManager()
- {
- clear();
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an empty QKeySequence object.
- \sa setValue()
- */
- QKeySequence QtKeySequencePropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QKeySequence());
- }
- /*!
- \reimp
- */
- QString QtKeySequencePropertyManager::valueText(const QtProperty *property) const
- {
- const QtKeySequencePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return it.value().toString(QKeySequence::NativeText);
- }
- /*!
- \fn void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &value)
- Sets the value of the given \a property to \a value.
- \sa value(), valueChanged()
- */
- void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &val)
- {
- setSimpleValue<const QKeySequence &, QKeySequence, QtKeySequencePropertyManager>(d_ptr->m_values, this,
- &QtKeySequencePropertyManager::propertyChanged,
- &QtKeySequencePropertyManager::valueChanged,
- property, val);
- }
- /*!
- \reimp
- */
- void QtKeySequencePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QKeySequence();
- }
- /*!
- \reimp
- */
- void QtKeySequencePropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtCharPropertyManager
- class QtCharPropertyManagerPrivate
- {
- QtCharPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtCharPropertyManager)
- public:
- typedef QMap<const QtProperty *, QChar> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*! \class QtCharPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtCharPropertyManager provides and manages QChar properties.
- A char's value can be retrieved using the value()
- function, and set using the setValue() slot.
- In addition, QtCharPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager
- */
- /*!
- \fn void QtCharPropertyManager::valueChanged(QtProperty *property, const QChar &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtCharPropertyManager::QtCharPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtCharPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtCharPropertyManager::~QtCharPropertyManager()
- {
- clear();
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an null QChar object.
- \sa setValue()
- */
- QChar QtCharPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QChar());
- }
- /*!
- \reimp
- */
- QString QtCharPropertyManager::valueText(const QtProperty *property) const
- {
- const QtCharPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QChar c = it.value();
- return c.isNull() ? QString() : QString(c);
- }
- /*!
- \fn void QtCharPropertyManager::setValue(QtProperty *property, const QChar &value)
- Sets the value of the given \a property to \a value.
- \sa value(), valueChanged()
- */
- void QtCharPropertyManager::setValue(QtProperty *property, const QChar &val)
- {
- setSimpleValue<const QChar &, QChar, QtCharPropertyManager>(d_ptr->m_values, this,
- &QtCharPropertyManager::propertyChanged,
- &QtCharPropertyManager::valueChanged,
- property, val);
- }
- /*!
- \reimp
- */
- void QtCharPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QChar();
- }
- /*!
- \reimp
- */
- void QtCharPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtLocalePropertyManager
- class QtLocalePropertyManagerPrivate
- {
- QtLocalePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtLocalePropertyManager)
- public:
- QtLocalePropertyManagerPrivate();
- void slotEnumChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- typedef QMap<const QtProperty *, QLocale> PropertyValueMap;
- PropertyValueMap m_values;
- QtEnumPropertyManager *m_enumPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToLanguage;
- QMap<const QtProperty *, QtProperty *> m_propertyToCountry;
- QMap<const QtProperty *, QtProperty *> m_languageToProperty;
- QMap<const QtProperty *, QtProperty *> m_countryToProperty;
- };
- QtLocalePropertyManagerPrivate::QtLocalePropertyManagerPrivate()
- {
- }
- void QtLocalePropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_languageToProperty.value(property, 0)) {
- const QLocale loc = m_values[prop];
- QLocale::Language newLanguage = loc.language();
- QLocale::Country newCountry = loc.country();
- metaEnumProvider()->indexToLocale(value, 0, &newLanguage, 0);
- QLocale newLoc(newLanguage, newCountry);
- q_ptr->setValue(prop, newLoc);
- } else if (QtProperty *prop = m_countryToProperty.value(property, 0)) {
- const QLocale loc = m_values[prop];
- QLocale::Language newLanguage = loc.language();
- QLocale::Country newCountry = loc.country();
- metaEnumProvider()->indexToLocale(m_enumPropertyManager->value(m_propertyToLanguage.value(prop)), value, &newLanguage, &newCountry);
- QLocale newLoc(newLanguage, newCountry);
- q_ptr->setValue(prop, newLoc);
- }
- }
- void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *subProp = m_languageToProperty.value(property, 0)) {
- m_propertyToLanguage[subProp] = 0;
- m_languageToProperty.remove(property);
- } else if (QtProperty *subProp = m_countryToProperty.value(property, 0)) {
- m_propertyToCountry[subProp] = 0;
- m_countryToProperty.remove(property);
- }
- }
- /*!
- \class QtLocalePropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtLocalePropertyManager provides and manages QLocale properties.
- A locale property has nested \e language and \e country
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by QtEnumPropertyManager object.
- These submanager can be retrieved using the subEnumPropertyManager()
- function. In order to provide editing widgets for the subproperties
- in a property browser widget, this manager must be associated with editor factory.
- In addition, QtLocalePropertyManager provides the valueChanged()
- signal which is emitted whenever a property created by this
- manager changes.
- \sa QtAbstractPropertyManager, QtEnumPropertyManager
- */
- /*!
- \fn void QtLocalePropertyManager::valueChanged(QtProperty *property, const QLocale &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtLocalePropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
- connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
- this, SLOT(slotEnumChanged(QtProperty*,int)));
- connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtLocalePropertyManager::~QtLocalePropertyManager()
- {
- clear();
- }
- /*!
- Returns the manager that creates the nested \e language
- and \e country subproperties.
- In order to provide editing widgets for the mentioned subproperties
- in a property browser widget, this manager must be associated with
- an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtEnumPropertyManager *QtLocalePropertyManager::subEnumPropertyManager() const
- {
- return d_ptr->m_enumPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns the default locale.
- \sa setValue()
- */
- QLocale QtLocalePropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QLocale());
- }
- /*!
- \reimp
- */
- QString QtLocalePropertyManager::valueText(const QtProperty *property) const
- {
- const QtLocalePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QLocale loc = it.value();
- int langIdx = 0;
- int countryIdx = 0;
- const QtMetaEnumProvider *me = metaEnumProvider();
- me->localeToIndex(loc.language(), loc.country(), &langIdx, &countryIdx);
- if (langIdx < 0) {
- qWarning("QtLocalePropertyManager::valueText: Unknown language %d", loc.language());
- return tr("<Invalid>");
- }
- const QString languageName = me->languageEnumNames().at(langIdx);
- if (countryIdx < 0) {
- qWarning("QtLocalePropertyManager::valueText: Unknown country %d for %s", loc.country(), qPrintable(languageName));
- return languageName;
- }
- const QString countryName = me->countryEnumNames(loc.language()).at(countryIdx);
- return tr("%1, %2").arg(languageName, countryName);
- }
- /*!
- \fn void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &val)
- {
- const QtLocalePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- const QLocale loc = it.value();
- if (loc == val)
- return;
- it.value() = val;
- int langIdx = 0;
- int countryIdx = 0;
- metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
- if (loc.language() != val.language()) {
- d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToLanguage.value(property), langIdx);
- d_ptr->m_enumPropertyManager->setEnumNames(d_ptr->m_propertyToCountry.value(property),
- metaEnumProvider()->countryEnumNames(val.language()));
- }
- d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToCountry.value(property), countryIdx);
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \reimp
- */
- void QtLocalePropertyManager::initializeProperty(QtProperty *property)
- {
- QLocale val;
- d_ptr->m_values[property] = val;
- int langIdx = 0;
- int countryIdx = 0;
- metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
- QtProperty *languageProp = d_ptr->m_enumPropertyManager->addProperty();
- languageProp->setPropertyName(tr("Language"));
- d_ptr->m_enumPropertyManager->setEnumNames(languageProp, metaEnumProvider()->languageEnumNames());
- d_ptr->m_enumPropertyManager->setValue(languageProp, langIdx);
- d_ptr->m_propertyToLanguage[property] = languageProp;
- d_ptr->m_languageToProperty[languageProp] = property;
- property->addSubProperty(languageProp);
- QtProperty *countryProp = d_ptr->m_enumPropertyManager->addProperty();
- countryProp->setPropertyName(tr("Country"));
- d_ptr->m_enumPropertyManager->setEnumNames(countryProp, metaEnumProvider()->countryEnumNames(val.language()));
- d_ptr->m_enumPropertyManager->setValue(countryProp, countryIdx);
- d_ptr->m_propertyToCountry[property] = countryProp;
- d_ptr->m_countryToProperty[countryProp] = property;
- property->addSubProperty(countryProp);
- }
- /*!
- \reimp
- */
- void QtLocalePropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *languageProp = d_ptr->m_propertyToLanguage[property];
- if (languageProp) {
- d_ptr->m_languageToProperty.remove(languageProp);
- delete languageProp;
- }
- d_ptr->m_propertyToLanguage.remove(property);
- QtProperty *countryProp = d_ptr->m_propertyToCountry[property];
- if (countryProp) {
- d_ptr->m_countryToProperty.remove(countryProp);
- delete countryProp;
- }
- d_ptr->m_propertyToCountry.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtPointPropertyManager
- class QtPointPropertyManagerPrivate
- {
- QtPointPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtPointPropertyManager)
- public:
- void slotIntChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- typedef QMap<const QtProperty *, QPoint> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToX;
- QMap<const QtProperty *, QtProperty *> m_propertyToY;
- QMap<const QtProperty *, QtProperty *> m_xToProperty;
- QMap<const QtProperty *, QtProperty *> m_yToProperty;
- };
- void QtPointPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (QtProperty *xprop = m_xToProperty.value(property, 0)) {
- QPoint p = m_values[xprop];
- p.setX(value);
- q_ptr->setValue(xprop, p);
- } else if (QtProperty *yprop = m_yToProperty.value(property, 0)) {
- QPoint p = m_values[yprop];
- p.setY(value);
- q_ptr->setValue(yprop, p);
- }
- }
- void QtPointPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
- m_propertyToX[pointProp] = 0;
- m_xToProperty.remove(property);
- } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
- m_propertyToY[pointProp] = 0;
- m_yToProperty.remove(property);
- }
- }
- /*! \class QtPointPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtPointPropertyManager provides and manages QPoint properties.
- A point property has nested \e x and \e y subproperties. The
- top-level property's value can be retrieved using the value()
- function, and set using the setValue() slot.
- The subproperties are created by a QtIntPropertyManager object. This
- manager can be retrieved using the subIntPropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- In addition, QtPointPropertyManager provides the valueChanged() signal which
- is emitted whenever a property created by this manager changes.
- \sa QtAbstractPropertyManager, QtIntPropertyManager, QtPointFPropertyManager
- */
- /*!
- \fn void QtPointPropertyManager::valueChanged(QtProperty *property, const QPoint &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtPointPropertyManager::QtPointPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtPointPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
- this, SLOT(slotIntChanged(QtProperty*,int)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtPointPropertyManager::~QtPointPropertyManager()
- {
- clear();
- }
- /*!
- Returns the manager that creates the nested \e x and \e y
- subproperties.
- In order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtPointPropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns a point with coordinates (0, 0).
- \sa setValue()
- */
- QPoint QtPointPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QPoint());
- }
- /*!
- \reimp
- */
- QString QtPointPropertyManager::valueText(const QtProperty *property) const
- {
- const QtPointPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QPoint v = it.value();
- return tr("(%1, %2)").arg(QString::number(v.x()))
- .arg(QString::number(v.y()));
- }
- /*!
- \fn void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &val)
- {
- const QtPointPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- if (it.value() == val)
- return;
- it.value() = val;
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \reimp
- */
- void QtPointPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QPoint(0, 0);
- QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
- xProp->setPropertyName(tr("X"));
- d_ptr->m_intPropertyManager->setValue(xProp, 0);
- d_ptr->m_propertyToX[property] = xProp;
- d_ptr->m_xToProperty[xProp] = property;
- property->addSubProperty(xProp);
- QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
- yProp->setPropertyName(tr("Y"));
- d_ptr->m_intPropertyManager->setValue(yProp, 0);
- d_ptr->m_propertyToY[property] = yProp;
- d_ptr->m_yToProperty[yProp] = property;
- property->addSubProperty(yProp);
- }
- /*!
- \reimp
- */
- void QtPointPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *xProp = d_ptr->m_propertyToX[property];
- if (xProp) {
- d_ptr->m_xToProperty.remove(xProp);
- delete xProp;
- }
- d_ptr->m_propertyToX.remove(property);
- QtProperty *yProp = d_ptr->m_propertyToY[property];
- if (yProp) {
- d_ptr->m_yToProperty.remove(yProp);
- delete yProp;
- }
- d_ptr->m_propertyToY.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtPointFPropertyManager
- class QtPointFPropertyManagerPrivate
- {
- QtPointFPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtPointFPropertyManager)
- public:
- struct Data
- {
- QPointF val;
- int decimals{2};
- };
- void slotDoubleChanged(QtProperty *property, double value);
- void slotPropertyDestroyed(QtProperty *property);
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtDoublePropertyManager *m_doublePropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToX;
- QMap<const QtProperty *, QtProperty *> m_propertyToY;
- QMap<const QtProperty *, QtProperty *> m_xToProperty;
- QMap<const QtProperty *, QtProperty *> m_yToProperty;
- };
- void QtPointFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
- {
- if (QtProperty *prop = m_xToProperty.value(property, 0)) {
- QPointF p = m_values[prop].val;
- p.setX(value);
- q_ptr->setValue(prop, p);
- } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
- QPointF p = m_values[prop].val;
- p.setY(value);
- q_ptr->setValue(prop, p);
- }
- }
- void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
- m_propertyToX[pointProp] = 0;
- m_xToProperty.remove(property);
- } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
- m_propertyToY[pointProp] = 0;
- m_yToProperty.remove(property);
- }
- }
- /*! \class QtPointFPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtPointFPropertyManager provides and manages QPointF properties.
- A point property has nested \e x and \e y subproperties. The
- top-level property's value can be retrieved using the value()
- function, and set using the setValue() slot.
- The subproperties are created by a QtDoublePropertyManager object. This
- manager can be retrieved using the subDoublePropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- In addition, QtPointFPropertyManager provides the valueChanged() signal which
- is emitted whenever a property created by this manager changes.
- \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtPointPropertyManager
- */
- /*!
- \fn void QtPointFPropertyManager::valueChanged(QtProperty *property, const QPointF &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtPointFPropertyManager::decimalsChanged(QtProperty *property, int prec)
- This signal is emitted whenever a property created by this manager
- changes its precision of value, passing a pointer to the
- \a property and the new \a prec value
- \sa setDecimals()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtPointFPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
- connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
- this, SLOT(slotDoubleChanged(QtProperty*,double)));
- connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtPointFPropertyManager::~QtPointFPropertyManager()
- {
- clear();
- }
- /*!
- Returns the manager that creates the nested \e x and \e y
- subproperties.
- In order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtDoublePropertyManager *QtPointFPropertyManager::subDoublePropertyManager() const
- {
- return d_ptr->m_doublePropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns a point with coordinates (0, 0).
- \sa setValue()
- */
- QPointF QtPointFPropertyManager::value(const QtProperty *property) const
- {
- return getValue<QPointF>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's precision, in decimals.
- \sa setDecimals()
- */
- int QtPointFPropertyManager::decimals(const QtProperty *property) const
- {
- return getData<int>(d_ptr->m_values, &QtPointFPropertyManagerPrivate::Data::decimals, property, 0);
- }
- /*!
- \reimp
- */
- QString QtPointFPropertyManager::valueText(const QtProperty *property) const
- {
- const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QPointF v = it.value().val;
- const int dec = it.value().decimals;
- return tr("(%1, %2)").arg(QString::number(v.x(), 'f', dec))
- .arg(QString::number(v.y(), 'f', dec));
- }
- /*!
- \fn void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &val)
- {
- const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- if (it.value().val == val)
- return;
- it.value().val = val;
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \fn void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
- Sets the precision of the given \a property to \a prec.
- The valid decimal range is 0-13. The default is 2.
- \sa decimals()
- */
- void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
- {
- const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtPointFPropertyManagerPrivate::Data data = it.value();
- if (prec > 13)
- prec = 13;
- else if (prec < 0)
- prec = 0;
- if (data.decimals == prec)
- return;
- data.decimals = prec;
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
- it.value() = data;
- emit decimalsChanged(property, data.decimals);
- }
- /*!
- \reimp
- */
- void QtPointFPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtPointFPropertyManagerPrivate::Data();
- QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
- xProp->setPropertyName(tr("X"));
- d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(xProp, 0);
- d_ptr->m_propertyToX[property] = xProp;
- d_ptr->m_xToProperty[xProp] = property;
- property->addSubProperty(xProp);
- QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
- yProp->setPropertyName(tr("Y"));
- d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(yProp, 0);
- d_ptr->m_propertyToY[property] = yProp;
- d_ptr->m_yToProperty[yProp] = property;
- property->addSubProperty(yProp);
- }
- /*!
- \reimp
- */
- void QtPointFPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *xProp = d_ptr->m_propertyToX[property];
- if (xProp) {
- d_ptr->m_xToProperty.remove(xProp);
- delete xProp;
- }
- d_ptr->m_propertyToX.remove(property);
- QtProperty *yProp = d_ptr->m_propertyToY[property];
- if (yProp) {
- d_ptr->m_yToProperty.remove(yProp);
- delete yProp;
- }
- d_ptr->m_propertyToY.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtSizePropertyManager
- class QtSizePropertyManagerPrivate
- {
- QtSizePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtSizePropertyManager)
- public:
- void slotIntChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- void setValue(QtProperty *property, const QSize &val);
- void setRange(QtProperty *property,
- const QSize &minVal, const QSize &maxVal, const QSize &val);
- struct Data
- {
- QSize val{0, 0};
- QSize minVal{0, 0};
- QSize maxVal{INT_MAX, INT_MAX};
- QSize minimumValue() const { return minVal; }
- QSize maximumValue() const { return maxVal; }
- void setMinimumValue(const QSize &newMinVal) { setSizeMinimumData(this, newMinVal); }
- void setMaximumValue(const QSize &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToW;
- QMap<const QtProperty *, QtProperty *> m_propertyToH;
- QMap<const QtProperty *, QtProperty *> m_wToProperty;
- QMap<const QtProperty *, QtProperty *> m_hToProperty;
- };
- void QtSizePropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_wToProperty.value(property, 0)) {
- QSize s = m_values[prop].val;
- s.setWidth(value);
- q_ptr->setValue(prop, s);
- } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
- QSize s = m_values[prop].val;
- s.setHeight(value);
- q_ptr->setValue(prop, s);
- }
- }
- void QtSizePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
- m_propertyToW[pointProp] = 0;
- m_wToProperty.remove(property);
- } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
- m_propertyToH[pointProp] = 0;
- m_hToProperty.remove(property);
- }
- }
- void QtSizePropertyManagerPrivate::setValue(QtProperty *property, const QSize &val)
- {
- m_intPropertyManager->setValue(m_propertyToW.value(property), val.width());
- m_intPropertyManager->setValue(m_propertyToH.value(property), val.height());
- }
- void QtSizePropertyManagerPrivate::setRange(QtProperty *property,
- const QSize &minVal, const QSize &maxVal, const QSize &val)
- {
- QtProperty *wProperty = m_propertyToW.value(property);
- QtProperty *hProperty = m_propertyToH.value(property);
- m_intPropertyManager->setRange(wProperty, minVal.width(), maxVal.width());
- m_intPropertyManager->setValue(wProperty, val.width());
- m_intPropertyManager->setRange(hProperty, minVal.height(), maxVal.height());
- m_intPropertyManager->setValue(hProperty, val.height());
- }
- /*!
- \class QtSizePropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtSizePropertyManager provides and manages QSize properties.
- A size property has nested \e width and \e height
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by a QtIntPropertyManager object. This
- manager can be retrieved using the subIntPropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- A size property also has a range of valid values defined by a
- minimum size and a maximum size. These sizes can be retrieved
- using the minimum() and the maximum() functions, and set using the
- setMinimum() and setMaximum() slots. Alternatively, the range can
- be defined in one go using the setRange() slot.
- In addition, QtSizePropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the rangeChanged() signal which is emitted whenever
- such a property changes its range of valid sizes.
- \sa QtAbstractPropertyManager, QtIntPropertyManager, QtSizeFPropertyManager
- */
- /*!
- \fn void QtSizePropertyManager::valueChanged(QtProperty *property, const QSize &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtSizePropertyManager::rangeChanged(QtProperty *property, const QSize &minimum, const QSize &maximum)
- This signal is emitted whenever a property created by this manager
- changes its range of valid sizes, passing a pointer to the \a
- property and the new \a minimum and \a maximum sizes.
- \sa setRange()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtSizePropertyManager::QtSizePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtSizePropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
- this, SLOT(slotIntChanged(QtProperty*,int)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtSizePropertyManager::~QtSizePropertyManager()
- {
- clear();
- }
- /*!
- Returns the manager that creates the nested \e width and \e height
- subproperties.
- In order to provide editing widgets for the \e width and \e height
- properties in a property browser widget, this manager must be
- associated with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtSizePropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an invalid size
- \sa setValue()
- */
- QSize QtSizePropertyManager::value(const QtProperty *property) const
- {
- return getValue<QSize>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's minimum size value.
- \sa setMinimum(), maximum(), setRange()
- */
- QSize QtSizePropertyManager::minimum(const QtProperty *property) const
- {
- return getMinimum<QSize>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's maximum size value.
- \sa setMaximum(), minimum(), setRange()
- */
- QSize QtSizePropertyManager::maximum(const QtProperty *property) const
- {
- return getMaximum<QSize>(d_ptr->m_values, property);
- }
- /*!
- \reimp
- */
- QString QtSizePropertyManager::valueText(const QtProperty *property) const
- {
- const QtSizePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QSize v = it.value().val;
- return tr("%1 x %2").arg(QString::number(v.width()))
- .arg(QString::number(v.height()));
- }
- /*!
- \fn void QtSizePropertyManager::setValue(QtProperty *property, const QSize &value)
- Sets the value of the given \a property to \a value.
- If the specified \a value is not valid according to the given \a
- property's size range, the \a value is adjusted to the nearest
- valid value within the size range.
- \sa value(), setRange(), valueChanged()
- */
- void QtSizePropertyManager::setValue(QtProperty *property, const QSize &val)
- {
- setValueInRange<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, const QSize>(this, d_ptr.data(),
- &QtSizePropertyManager::propertyChanged,
- &QtSizePropertyManager::valueChanged,
- property, val, &QtSizePropertyManagerPrivate::setValue);
- }
- /*!
- Sets the minimum size value for the given \a property to \a minVal.
- When setting the minimum size value, the maximum and current
- values are adjusted if necessary (ensuring that the size range
- remains valid and that the current value is within the range).
- \sa minimum(), setRange(), rangeChanged()
- */
- void QtSizePropertyManager::setMinimum(QtProperty *property, const QSize &minVal)
- {
- setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr.data(),
- &QtSizePropertyManager::propertyChanged,
- &QtSizePropertyManager::valueChanged,
- &QtSizePropertyManager::rangeChanged,
- property,
- &QtSizePropertyManagerPrivate::Data::minimumValue,
- &QtSizePropertyManagerPrivate::Data::setMinimumValue,
- minVal, &QtSizePropertyManagerPrivate::setRange);
- }
- /*!
- Sets the maximum size value for the given \a property to \a maxVal.
- When setting the maximum size value, the minimum and current
- values are adjusted if necessary (ensuring that the size range
- remains valid and that the current value is within the range).
- \sa maximum(), setRange(), rangeChanged()
- */
- void QtSizePropertyManager::setMaximum(QtProperty *property, const QSize &maxVal)
- {
- setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr.data(),
- &QtSizePropertyManager::propertyChanged,
- &QtSizePropertyManager::valueChanged,
- &QtSizePropertyManager::rangeChanged,
- property,
- &QtSizePropertyManagerPrivate::Data::maximumValue,
- &QtSizePropertyManagerPrivate::Data::setMaximumValue,
- maxVal, &QtSizePropertyManagerPrivate::setRange);
- }
- /*!
- \fn void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minimum, const QSize &maximum)
- Sets the range of valid values.
- This is a convenience function defining the range of valid values
- in one go; setting the \a minimum and \a maximum values for the
- given \a property with a single function call.
- When setting a new range, the current value is adjusted if
- necessary (ensuring that the value remains within the range).
- \sa setMinimum(), setMaximum(), rangeChanged()
- */
- void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minVal, const QSize &maxVal)
- {
- setBorderValues<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize>(this, d_ptr.data(),
- &QtSizePropertyManager::propertyChanged,
- &QtSizePropertyManager::valueChanged,
- &QtSizePropertyManager::rangeChanged,
- property, minVal, maxVal, &QtSizePropertyManagerPrivate::setRange);
- }
- /*!
- \reimp
- */
- void QtSizePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtSizePropertyManagerPrivate::Data();
- QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
- wProp->setPropertyName(tr("Width"));
- d_ptr->m_intPropertyManager->setValue(wProp, 0);
- d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
- d_ptr->m_propertyToW[property] = wProp;
- d_ptr->m_wToProperty[wProp] = property;
- property->addSubProperty(wProp);
- QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
- hProp->setPropertyName(tr("Height"));
- d_ptr->m_intPropertyManager->setValue(hProp, 0);
- d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
- d_ptr->m_propertyToH[property] = hProp;
- d_ptr->m_hToProperty[hProp] = property;
- property->addSubProperty(hProp);
- }
- /*!
- \reimp
- */
- void QtSizePropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *wProp = d_ptr->m_propertyToW[property];
- if (wProp) {
- d_ptr->m_wToProperty.remove(wProp);
- delete wProp;
- }
- d_ptr->m_propertyToW.remove(property);
- QtProperty *hProp = d_ptr->m_propertyToH[property];
- if (hProp) {
- d_ptr->m_hToProperty.remove(hProp);
- delete hProp;
- }
- d_ptr->m_propertyToH.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtSizeFPropertyManager
- class QtSizeFPropertyManagerPrivate
- {
- QtSizeFPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtSizeFPropertyManager)
- public:
- void slotDoubleChanged(QtProperty *property, double value);
- void slotPropertyDestroyed(QtProperty *property);
- void setValue(QtProperty *property, const QSizeF &val);
- void setRange(QtProperty *property,
- const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val);
- struct Data
- {
- QSizeF val{0, 0};
- QSizeF minVal{0, 0};
- QSizeF maxVal{std::numeric_limits<qreal>::max(), std::numeric_limits<qreal>::max()};
- int decimals{2};
- QSizeF minimumValue() const { return minVal; }
- QSizeF maximumValue() const { return maxVal; }
- void setMinimumValue(const QSizeF &newMinVal) { setSizeMinimumData(this, newMinVal); }
- void setMaximumValue(const QSizeF &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtDoublePropertyManager *m_doublePropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToW;
- QMap<const QtProperty *, QtProperty *> m_propertyToH;
- QMap<const QtProperty *, QtProperty *> m_wToProperty;
- QMap<const QtProperty *, QtProperty *> m_hToProperty;
- };
- void QtSizeFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
- {
- if (QtProperty *prop = m_wToProperty.value(property, 0)) {
- QSizeF s = m_values[prop].val;
- s.setWidth(value);
- q_ptr->setValue(prop, s);
- } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
- QSizeF s = m_values[prop].val;
- s.setHeight(value);
- q_ptr->setValue(prop, s);
- }
- }
- void QtSizeFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
- m_propertyToW[pointProp] = 0;
- m_wToProperty.remove(property);
- } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
- m_propertyToH[pointProp] = 0;
- m_hToProperty.remove(property);
- }
- }
- void QtSizeFPropertyManagerPrivate::setValue(QtProperty *property, const QSizeF &val)
- {
- m_doublePropertyManager->setValue(m_propertyToW.value(property), val.width());
- m_doublePropertyManager->setValue(m_propertyToH.value(property), val.height());
- }
- void QtSizeFPropertyManagerPrivate::setRange(QtProperty *property,
- const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val)
- {
- m_doublePropertyManager->setRange(m_propertyToW[property], minVal.width(), maxVal.width());
- m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
- m_doublePropertyManager->setRange(m_propertyToH[property], minVal.height(), maxVal.height());
- m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
- }
- /*!
- \class QtSizeFPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtSizeFPropertyManager provides and manages QSizeF properties.
- A size property has nested \e width and \e height
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by a QtDoublePropertyManager object. This
- manager can be retrieved using the subDoublePropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- A size property also has a range of valid values defined by a
- minimum size and a maximum size. These sizes can be retrieved
- using the minimum() and the maximum() functions, and set using the
- setMinimum() and setMaximum() slots. Alternatively, the range can
- be defined in one go using the setRange() slot.
- In addition, QtSizeFPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the rangeChanged() signal which is emitted whenever
- such a property changes its range of valid sizes.
- \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtSizePropertyManager
- */
- /*!
- \fn void QtSizeFPropertyManager::valueChanged(QtProperty *property, const QSizeF &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtSizeFPropertyManager::rangeChanged(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
- This signal is emitted whenever a property created by this manager
- changes its range of valid sizes, passing a pointer to the \a
- property and the new \a minimum and \a maximum sizes.
- \sa setRange()
- */
- /*!
- \fn void QtSizeFPropertyManager::decimalsChanged(QtProperty *property, int prec)
- This signal is emitted whenever a property created by this manager
- changes its precision of value, passing a pointer to the
- \a property and the new \a prec value
- \sa setDecimals()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtSizeFPropertyManager::QtSizeFPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtSizeFPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
- connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
- this, SLOT(slotDoubleChanged(QtProperty*,double)));
- connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtSizeFPropertyManager::~QtSizeFPropertyManager()
- {
- clear();
- }
- /*!
- Returns the manager that creates the nested \e width and \e height
- subproperties.
- In order to provide editing widgets for the \e width and \e height
- properties in a property browser widget, this manager must be
- associated with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtDoublePropertyManager *QtSizeFPropertyManager::subDoublePropertyManager() const
- {
- return d_ptr->m_doublePropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an invalid size
- \sa setValue()
- */
- QSizeF QtSizeFPropertyManager::value(const QtProperty *property) const
- {
- return getValue<QSizeF>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's precision, in decimals.
- \sa setDecimals()
- */
- int QtSizeFPropertyManager::decimals(const QtProperty *property) const
- {
- return getData<int>(d_ptr->m_values, &QtSizeFPropertyManagerPrivate::Data::decimals, property, 0);
- }
- /*!
- Returns the given \a property's minimum size value.
- \sa setMinimum(), maximum(), setRange()
- */
- QSizeF QtSizeFPropertyManager::minimum(const QtProperty *property) const
- {
- return getMinimum<QSizeF>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's maximum size value.
- \sa setMaximum(), minimum(), setRange()
- */
- QSizeF QtSizeFPropertyManager::maximum(const QtProperty *property) const
- {
- return getMaximum<QSizeF>(d_ptr->m_values, property);
- }
- /*!
- \reimp
- */
- QString QtSizeFPropertyManager::valueText(const QtProperty *property) const
- {
- const QtSizeFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QSizeF v = it.value().val;
- const int dec = it.value().decimals;
- return tr("%1 x %2").arg(QString::number(v.width(), 'f', dec))
- .arg(QString::number(v.height(), 'f', dec));
- }
- /*!
- \fn void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &value)
- Sets the value of the given \a property to \a value.
- If the specified \a value is not valid according to the given \a
- property's size range, the \a value is adjusted to the nearest
- valid value within the size range.
- \sa value(), setRange(), valueChanged()
- */
- void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &val)
- {
- setValueInRange<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr.data(),
- &QtSizeFPropertyManager::propertyChanged,
- &QtSizeFPropertyManager::valueChanged,
- property, val, &QtSizeFPropertyManagerPrivate::setValue);
- }
- /*!
- \fn void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
- Sets the precision of the given \a property to \a prec.
- The valid decimal range is 0-13. The default is 2.
- \sa decimals()
- */
- void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
- {
- const QtSizeFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtSizeFPropertyManagerPrivate::Data data = it.value();
- if (prec > 13)
- prec = 13;
- else if (prec < 0)
- prec = 0;
- if (data.decimals == prec)
- return;
- data.decimals = prec;
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
- it.value() = data;
- emit decimalsChanged(property, data.decimals);
- }
- /*!
- Sets the minimum size value for the given \a property to \a minVal.
- When setting the minimum size value, the maximum and current
- values are adjusted if necessary (ensuring that the size range
- remains valid and that the current value is within the range).
- \sa minimum(), setRange(), rangeChanged()
- */
- void QtSizeFPropertyManager::setMinimum(QtProperty *property, const QSizeF &minVal)
- {
- setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr.data(),
- &QtSizeFPropertyManager::propertyChanged,
- &QtSizeFPropertyManager::valueChanged,
- &QtSizeFPropertyManager::rangeChanged,
- property,
- &QtSizeFPropertyManagerPrivate::Data::minimumValue,
- &QtSizeFPropertyManagerPrivate::Data::setMinimumValue,
- minVal, &QtSizeFPropertyManagerPrivate::setRange);
- }
- /*!
- Sets the maximum size value for the given \a property to \a maxVal.
- When setting the maximum size value, the minimum and current
- values are adjusted if necessary (ensuring that the size range
- remains valid and that the current value is within the range).
- \sa maximum(), setRange(), rangeChanged()
- */
- void QtSizeFPropertyManager::setMaximum(QtProperty *property, const QSizeF &maxVal)
- {
- setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr.data(),
- &QtSizeFPropertyManager::propertyChanged,
- &QtSizeFPropertyManager::valueChanged,
- &QtSizeFPropertyManager::rangeChanged,
- property,
- &QtSizeFPropertyManagerPrivate::Data::maximumValue,
- &QtSizeFPropertyManagerPrivate::Data::setMaximumValue,
- maxVal, &QtSizeFPropertyManagerPrivate::setRange);
- }
- /*!
- \fn void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
- Sets the range of valid values.
- This is a convenience function defining the range of valid values
- in one go; setting the \a minimum and \a maximum values for the
- given \a property with a single function call.
- When setting a new range, the current value is adjusted if
- necessary (ensuring that the value remains within the range).
- \sa setMinimum(), setMaximum(), rangeChanged()
- */
- void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minVal, const QSizeF &maxVal)
- {
- setBorderValues<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr.data(),
- &QtSizeFPropertyManager::propertyChanged,
- &QtSizeFPropertyManager::valueChanged,
- &QtSizeFPropertyManager::rangeChanged,
- property, minVal, maxVal, &QtSizeFPropertyManagerPrivate::setRange);
- }
- /*!
- \reimp
- */
- void QtSizeFPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtSizeFPropertyManagerPrivate::Data();
- QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
- wProp->setPropertyName(tr("Width"));
- d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(wProp, 0);
- d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
- d_ptr->m_propertyToW[property] = wProp;
- d_ptr->m_wToProperty[wProp] = property;
- property->addSubProperty(wProp);
- QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
- hProp->setPropertyName(tr("Height"));
- d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(hProp, 0);
- d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
- d_ptr->m_propertyToH[property] = hProp;
- d_ptr->m_hToProperty[hProp] = property;
- property->addSubProperty(hProp);
- }
- /*!
- \reimp
- */
- void QtSizeFPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *wProp = d_ptr->m_propertyToW[property];
- if (wProp) {
- d_ptr->m_wToProperty.remove(wProp);
- delete wProp;
- }
- d_ptr->m_propertyToW.remove(property);
- QtProperty *hProp = d_ptr->m_propertyToH[property];
- if (hProp) {
- d_ptr->m_hToProperty.remove(hProp);
- delete hProp;
- }
- d_ptr->m_propertyToH.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtRectPropertyManager
- class QtRectPropertyManagerPrivate
- {
- QtRectPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtRectPropertyManager)
- public:
- void slotIntChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- void setConstraint(QtProperty *property, const QRect &constraint, const QRect &val);
- struct Data
- {
- QRect val{0, 0, 0, 0};
- QRect constraint;
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToX;
- QMap<const QtProperty *, QtProperty *> m_propertyToY;
- QMap<const QtProperty *, QtProperty *> m_propertyToW;
- QMap<const QtProperty *, QtProperty *> m_propertyToH;
- QMap<const QtProperty *, QtProperty *> m_xToProperty;
- QMap<const QtProperty *, QtProperty *> m_yToProperty;
- QMap<const QtProperty *, QtProperty *> m_wToProperty;
- QMap<const QtProperty *, QtProperty *> m_hToProperty;
- };
- void QtRectPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_xToProperty.value(property, 0)) {
- QRect r = m_values[prop].val;
- r.moveLeft(value);
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_yToProperty.value(property)) {
- QRect r = m_values[prop].val;
- r.moveTop(value);
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
- Data data = m_values[prop];
- QRect r = data.val;
- r.setWidth(value);
- if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
- r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
- }
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
- Data data = m_values[prop];
- QRect r = data.val;
- r.setHeight(value);
- if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
- r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
- }
- q_ptr->setValue(prop, r);
- }
- }
- void QtRectPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
- m_propertyToX[pointProp] = 0;
- m_xToProperty.remove(property);
- } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
- m_propertyToY[pointProp] = 0;
- m_yToProperty.remove(property);
- } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
- m_propertyToW[pointProp] = 0;
- m_wToProperty.remove(property);
- } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
- m_propertyToH[pointProp] = 0;
- m_hToProperty.remove(property);
- }
- }
- void QtRectPropertyManagerPrivate::setConstraint(QtProperty *property,
- const QRect &constraint, const QRect &val)
- {
- const bool isNull = constraint.isNull();
- const int left = isNull ? INT_MIN : constraint.left();
- const int right = isNull ? INT_MAX : constraint.left() + constraint.width();
- const int top = isNull ? INT_MIN : constraint.top();
- const int bottom = isNull ? INT_MAX : constraint.top() + constraint.height();
- const int width = isNull ? INT_MAX : constraint.width();
- const int height = isNull ? INT_MAX : constraint.height();
- m_intPropertyManager->setRange(m_propertyToX[property], left, right);
- m_intPropertyManager->setRange(m_propertyToY[property], top, bottom);
- m_intPropertyManager->setRange(m_propertyToW[property], 0, width);
- m_intPropertyManager->setRange(m_propertyToH[property], 0, height);
- m_intPropertyManager->setValue(m_propertyToX[property], val.x());
- m_intPropertyManager->setValue(m_propertyToY[property], val.y());
- m_intPropertyManager->setValue(m_propertyToW[property], val.width());
- m_intPropertyManager->setValue(m_propertyToH[property], val.height());
- }
- /*!
- \class QtRectPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtRectPropertyManager provides and manages QRect properties.
- A rectangle property has nested \e x, \e y, \e width and \e height
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by a QtIntPropertyManager object. This
- manager can be retrieved using the subIntPropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- A rectangle property also has a constraint rectangle which can be
- retrieved using the constraint() function, and set using the
- setConstraint() slot.
- In addition, QtRectPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the constraintChanged() signal which is emitted
- whenever such a property changes its constraint rectangle.
- \sa QtAbstractPropertyManager, QtIntPropertyManager, QtRectFPropertyManager
- */
- /*!
- \fn void QtRectPropertyManager::valueChanged(QtProperty *property, const QRect &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtRectPropertyManager::constraintChanged(QtProperty *property, const QRect &constraint)
- This signal is emitted whenever property changes its constraint
- rectangle, passing a pointer to the \a property and the new \a
- constraint rectangle as parameters.
- \sa setConstraint()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtRectPropertyManager::QtRectPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtRectPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
- this, SLOT(slotIntChanged(QtProperty*,int)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtRectPropertyManager::~QtRectPropertyManager()
- {
- clear();
- }
- /*!
- Returns the manager that creates the nested \e x, \e y, \e width
- and \e height subproperties.
- In order to provide editing widgets for the mentioned
- subproperties in a property browser widget, this manager must be
- associated with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtRectPropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an invalid rectangle.
- \sa setValue(), constraint()
- */
- QRect QtRectPropertyManager::value(const QtProperty *property) const
- {
- return getValue<QRect>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's constraining rectangle. If returned value is null QRect it means there is no constraint applied.
- \sa value(), setConstraint()
- */
- QRect QtRectPropertyManager::constraint(const QtProperty *property) const
- {
- return getData<QRect>(d_ptr->m_values, &QtRectPropertyManagerPrivate::Data::constraint, property, QRect());
- }
- /*!
- \reimp
- */
- QString QtRectPropertyManager::valueText(const QtProperty *property) const
- {
- const QtRectPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QRect v = it.value().val;
- return tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x()))
- .arg(QString::number(v.y()))
- .arg(QString::number(v.width()))
- .arg(QString::number(v.height()));
- }
- /*!
- \fn void QtRectPropertyManager::setValue(QtProperty *property, const QRect &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- If the specified \a value is not inside the given \a property's
- constraining rectangle, the value is adjusted accordingly to fit
- within the constraint.
- \sa value(), setConstraint(), valueChanged()
- */
- void QtRectPropertyManager::setValue(QtProperty *property, const QRect &val)
- {
- const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtRectPropertyManagerPrivate::Data data = it.value();
- QRect newRect = val.normalized();
- if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
- const QRect r1 = data.constraint;
- const QRect r2 = newRect;
- newRect.setLeft(qMax(r1.left(), r2.left()));
- newRect.setRight(qMin(r1.right(), r2.right()));
- newRect.setTop(qMax(r1.top(), r2.top()));
- newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
- if (newRect.width() < 0 || newRect.height() < 0)
- return;
- }
- if (data.val == newRect)
- return;
- data.val = newRect;
- it.value() = data;
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the given \a property's constraining rectangle to \a
- constraint.
- When setting the constraint, the current value is adjusted if
- necessary (ensuring that the current rectangle value is inside the
- constraint). In order to reset the constraint pass a null QRect value.
- \sa setValue(), constraint(), constraintChanged()
- */
- void QtRectPropertyManager::setConstraint(QtProperty *property, const QRect &constraint)
- {
- const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtRectPropertyManagerPrivate::Data data = it.value();
- QRect newConstraint = constraint.normalized();
- if (data.constraint == newConstraint)
- return;
- const QRect oldVal = data.val;
- data.constraint = newConstraint;
- if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
- QRect r1 = data.constraint;
- QRect r2 = data.val;
- if (r2.width() > r1.width())
- r2.setWidth(r1.width());
- if (r2.height() > r1.height())
- r2.setHeight(r1.height());
- if (r2.left() < r1.left())
- r2.moveLeft(r1.left());
- else if (r2.right() > r1.right())
- r2.moveRight(r1.right());
- if (r2.top() < r1.top())
- r2.moveTop(r1.top());
- else if (r2.bottom() > r1.bottom())
- r2.moveBottom(r1.bottom());
- data.val = r2;
- }
- it.value() = data;
- emit constraintChanged(property, data.constraint);
- d_ptr->setConstraint(property, data.constraint, data.val);
- if (data.val == oldVal)
- return;
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- \reimp
- */
- void QtRectPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtRectPropertyManagerPrivate::Data();
- QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
- xProp->setPropertyName(tr("X"));
- d_ptr->m_intPropertyManager->setValue(xProp, 0);
- d_ptr->m_propertyToX[property] = xProp;
- d_ptr->m_xToProperty[xProp] = property;
- property->addSubProperty(xProp);
- QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
- yProp->setPropertyName(tr("Y"));
- d_ptr->m_intPropertyManager->setValue(yProp, 0);
- d_ptr->m_propertyToY[property] = yProp;
- d_ptr->m_yToProperty[yProp] = property;
- property->addSubProperty(yProp);
- QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
- wProp->setPropertyName(tr("Width"));
- d_ptr->m_intPropertyManager->setValue(wProp, 0);
- d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
- d_ptr->m_propertyToW[property] = wProp;
- d_ptr->m_wToProperty[wProp] = property;
- property->addSubProperty(wProp);
- QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
- hProp->setPropertyName(tr("Height"));
- d_ptr->m_intPropertyManager->setValue(hProp, 0);
- d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
- d_ptr->m_propertyToH[property] = hProp;
- d_ptr->m_hToProperty[hProp] = property;
- property->addSubProperty(hProp);
- }
- /*!
- \reimp
- */
- void QtRectPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *xProp = d_ptr->m_propertyToX[property];
- if (xProp) {
- d_ptr->m_xToProperty.remove(xProp);
- delete xProp;
- }
- d_ptr->m_propertyToX.remove(property);
- QtProperty *yProp = d_ptr->m_propertyToY[property];
- if (yProp) {
- d_ptr->m_yToProperty.remove(yProp);
- delete yProp;
- }
- d_ptr->m_propertyToY.remove(property);
- QtProperty *wProp = d_ptr->m_propertyToW[property];
- if (wProp) {
- d_ptr->m_wToProperty.remove(wProp);
- delete wProp;
- }
- d_ptr->m_propertyToW.remove(property);
- QtProperty *hProp = d_ptr->m_propertyToH[property];
- if (hProp) {
- d_ptr->m_hToProperty.remove(hProp);
- delete hProp;
- }
- d_ptr->m_propertyToH.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtRectFPropertyManager
- class QtRectFPropertyManagerPrivate
- {
- QtRectFPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtRectFPropertyManager)
- public:
- void slotDoubleChanged(QtProperty *property, double value);
- void slotPropertyDestroyed(QtProperty *property);
- void setConstraint(QtProperty *property, const QRectF &constraint, const QRectF &val);
- struct Data
- {
- QRectF val{0, 0, 0, 0};
- QRectF constraint;
- int decimals{2};
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtDoublePropertyManager *m_doublePropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToX;
- QMap<const QtProperty *, QtProperty *> m_propertyToY;
- QMap<const QtProperty *, QtProperty *> m_propertyToW;
- QMap<const QtProperty *, QtProperty *> m_propertyToH;
- QMap<const QtProperty *, QtProperty *> m_xToProperty;
- QMap<const QtProperty *, QtProperty *> m_yToProperty;
- QMap<const QtProperty *, QtProperty *> m_wToProperty;
- QMap<const QtProperty *, QtProperty *> m_hToProperty;
- };
- void QtRectFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
- {
- if (QtProperty *prop = m_xToProperty.value(property, 0)) {
- QRectF r = m_values[prop].val;
- r.moveLeft(value);
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
- QRectF r = m_values[prop].val;
- r.moveTop(value);
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
- Data data = m_values[prop];
- QRectF r = data.val;
- r.setWidth(value);
- if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
- r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
- }
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
- Data data = m_values[prop];
- QRectF r = data.val;
- r.setHeight(value);
- if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
- r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
- }
- q_ptr->setValue(prop, r);
- }
- }
- void QtRectFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
- m_propertyToX[pointProp] = 0;
- m_xToProperty.remove(property);
- } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
- m_propertyToY[pointProp] = 0;
- m_yToProperty.remove(property);
- } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
- m_propertyToW[pointProp] = 0;
- m_wToProperty.remove(property);
- } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
- m_propertyToH[pointProp] = 0;
- m_hToProperty.remove(property);
- }
- }
- void QtRectFPropertyManagerPrivate::setConstraint(QtProperty *property,
- const QRectF &constraint, const QRectF &val)
- {
- const bool isNull = constraint.isNull();
- const float left = isNull ? FLT_MIN : constraint.left();
- const float right = isNull ? FLT_MAX : constraint.left() + constraint.width();
- const float top = isNull ? FLT_MIN : constraint.top();
- const float bottom = isNull ? FLT_MAX : constraint.top() + constraint.height();
- const float width = isNull ? FLT_MAX : constraint.width();
- const float height = isNull ? FLT_MAX : constraint.height();
- m_doublePropertyManager->setRange(m_propertyToX[property], left, right);
- m_doublePropertyManager->setRange(m_propertyToY[property], top, bottom);
- m_doublePropertyManager->setRange(m_propertyToW[property], 0, width);
- m_doublePropertyManager->setRange(m_propertyToH[property], 0, height);
- m_doublePropertyManager->setValue(m_propertyToX[property], val.x());
- m_doublePropertyManager->setValue(m_propertyToY[property], val.y());
- m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
- m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
- }
- /*!
- \class QtRectFPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtRectFPropertyManager provides and manages QRectF properties.
- A rectangle property has nested \e x, \e y, \e width and \e height
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by a QtDoublePropertyManager object. This
- manager can be retrieved using the subDoublePropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- A rectangle property also has a constraint rectangle which can be
- retrieved using the constraint() function, and set using the
- setConstraint() slot.
- In addition, QtRectFPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the constraintChanged() signal which is emitted
- whenever such a property changes its constraint rectangle.
- \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtRectPropertyManager
- */
- /*!
- \fn void QtRectFPropertyManager::valueChanged(QtProperty *property, const QRectF &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtRectFPropertyManager::constraintChanged(QtProperty *property, const QRectF &constraint)
- This signal is emitted whenever property changes its constraint
- rectangle, passing a pointer to the \a property and the new \a
- constraint rectangle as parameters.
- \sa setConstraint()
- */
- /*!
- \fn void QtRectFPropertyManager::decimalsChanged(QtProperty *property, int prec)
- This signal is emitted whenever a property created by this manager
- changes its precision of value, passing a pointer to the
- \a property and the new \a prec value
- \sa setDecimals()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtRectFPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
- connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
- this, SLOT(slotDoubleChanged(QtProperty*,double)));
- connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtRectFPropertyManager::~QtRectFPropertyManager()
- {
- clear();
- }
- /*!
- Returns the manager that creates the nested \e x, \e y, \e width
- and \e height subproperties.
- In order to provide editing widgets for the mentioned
- subproperties in a property browser widget, this manager must be
- associated with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtDoublePropertyManager *QtRectFPropertyManager::subDoublePropertyManager() const
- {
- return d_ptr->m_doublePropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an invalid rectangle.
- \sa setValue(), constraint()
- */
- QRectF QtRectFPropertyManager::value(const QtProperty *property) const
- {
- return getValue<QRectF>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's precision, in decimals.
- \sa setDecimals()
- */
- int QtRectFPropertyManager::decimals(const QtProperty *property) const
- {
- return getData<int>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::decimals, property, 0);
- }
- /*!
- Returns the given \a property's constraining rectangle. If returned value is null QRectF it means there is no constraint applied.
- \sa value(), setConstraint()
- */
- QRectF QtRectFPropertyManager::constraint(const QtProperty *property) const
- {
- return getData<QRectF>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::constraint, property, QRect());
- }
- /*!
- \reimp
- */
- QString QtRectFPropertyManager::valueText(const QtProperty *property) const
- {
- const QtRectFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QRectF v = it.value().val;
- const int dec = it.value().decimals;
- return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x(), 'f', dec))
- .arg(QString::number(v.y(), 'f', dec))
- .arg(QString::number(v.width(), 'f', dec))
- .arg(QString::number(v.height(), 'f', dec)));
- }
- /*!
- \fn void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- If the specified \a value is not inside the given \a property's
- constraining rectangle, the value is adjusted accordingly to fit
- within the constraint.
- \sa value(), setConstraint(), valueChanged()
- */
- void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &val)
- {
- const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtRectFPropertyManagerPrivate::Data data = it.value();
- QRectF newRect = val.normalized();
- if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
- const QRectF r1 = data.constraint;
- const QRectF r2 = newRect;
- newRect.setLeft(qMax(r1.left(), r2.left()));
- newRect.setRight(qMin(r1.right(), r2.right()));
- newRect.setTop(qMax(r1.top(), r2.top()));
- newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
- if (newRect.width() < 0 || newRect.height() < 0)
- return;
- }
- if (data.val == newRect)
- return;
- data.val = newRect;
- it.value() = data;
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the given \a property's constraining rectangle to \a
- constraint.
- When setting the constraint, the current value is adjusted if
- necessary (ensuring that the current rectangle value is inside the
- constraint). In order to reset the constraint pass a null QRectF value.
- \sa setValue(), constraint(), constraintChanged()
- */
- void QtRectFPropertyManager::setConstraint(QtProperty *property, const QRectF &constraint)
- {
- const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtRectFPropertyManagerPrivate::Data data = it.value();
- QRectF newConstraint = constraint.normalized();
- if (data.constraint == newConstraint)
- return;
- const QRectF oldVal = data.val;
- data.constraint = newConstraint;
- if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
- QRectF r1 = data.constraint;
- QRectF r2 = data.val;
- if (r2.width() > r1.width())
- r2.setWidth(r1.width());
- if (r2.height() > r1.height())
- r2.setHeight(r1.height());
- if (r2.left() < r1.left())
- r2.moveLeft(r1.left());
- else if (r2.right() > r1.right())
- r2.moveRight(r1.right());
- if (r2.top() < r1.top())
- r2.moveTop(r1.top());
- else if (r2.bottom() > r1.bottom())
- r2.moveBottom(r1.bottom());
- data.val = r2;
- }
- it.value() = data;
- emit constraintChanged(property, data.constraint);
- d_ptr->setConstraint(property, data.constraint, data.val);
- if (data.val == oldVal)
- return;
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- \fn void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
- Sets the precision of the given \a property to \a prec.
- The valid decimal range is 0-13. The default is 2.
- \sa decimals()
- */
- void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
- {
- const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtRectFPropertyManagerPrivate::Data data = it.value();
- if (prec > 13)
- prec = 13;
- else if (prec < 0)
- prec = 0;
- if (data.decimals == prec)
- return;
- data.decimals = prec;
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
- it.value() = data;
- emit decimalsChanged(property, data.decimals);
- }
- /*!
- \reimp
- */
- void QtRectFPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtRectFPropertyManagerPrivate::Data();
- QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
- xProp->setPropertyName(tr("X"));
- d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(xProp, 0);
- d_ptr->m_propertyToX[property] = xProp;
- d_ptr->m_xToProperty[xProp] = property;
- property->addSubProperty(xProp);
- QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
- yProp->setPropertyName(tr("Y"));
- d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(yProp, 0);
- d_ptr->m_propertyToY[property] = yProp;
- d_ptr->m_yToProperty[yProp] = property;
- property->addSubProperty(yProp);
- QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
- wProp->setPropertyName(tr("Width"));
- d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(wProp, 0);
- d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
- d_ptr->m_propertyToW[property] = wProp;
- d_ptr->m_wToProperty[wProp] = property;
- property->addSubProperty(wProp);
- QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
- hProp->setPropertyName(tr("Height"));
- d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(hProp, 0);
- d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
- d_ptr->m_propertyToH[property] = hProp;
- d_ptr->m_hToProperty[hProp] = property;
- property->addSubProperty(hProp);
- }
- /*!
- \reimp
- */
- void QtRectFPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *xProp = d_ptr->m_propertyToX[property];
- if (xProp) {
- d_ptr->m_xToProperty.remove(xProp);
- delete xProp;
- }
- d_ptr->m_propertyToX.remove(property);
- QtProperty *yProp = d_ptr->m_propertyToY[property];
- if (yProp) {
- d_ptr->m_yToProperty.remove(yProp);
- delete yProp;
- }
- d_ptr->m_propertyToY.remove(property);
- QtProperty *wProp = d_ptr->m_propertyToW[property];
- if (wProp) {
- d_ptr->m_wToProperty.remove(wProp);
- delete wProp;
- }
- d_ptr->m_propertyToW.remove(property);
- QtProperty *hProp = d_ptr->m_propertyToH[property];
- if (hProp) {
- d_ptr->m_hToProperty.remove(hProp);
- delete hProp;
- }
- d_ptr->m_propertyToH.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtEnumPropertyManager
- class QtEnumPropertyManagerPrivate
- {
- QtEnumPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtEnumPropertyManager)
- public:
- struct Data
- {
- int val{-1};
- QStringList enumNames;
- QMap<int, QIcon> enumIcons;
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*!
- \class QtEnumPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtEnumPropertyManager provides and manages enum properties.
- Each enum property has an associated list of enum names which can
- be retrieved using the enumNames() function, and set using the
- corresponding setEnumNames() function. An enum property's value is
- represented by an index in this list, and can be retrieved and set
- using the value() and setValue() slots respectively.
- Each enum value can also have an associated icon. The mapping from
- values to icons can be set using the setEnumIcons() function and
- queried with the enumIcons() function.
- In addition, QtEnumPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes. The enumNamesChanged() or enumIconsChanged() signal is emitted
- whenever the list of enum names or icons is altered.
- \sa QtAbstractPropertyManager, QtEnumEditorFactory
- */
- /*!
- \fn void QtEnumPropertyManager::valueChanged(QtProperty *property, int value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtEnumPropertyManager::enumNamesChanged(QtProperty *property, const QStringList &names)
- This signal is emitted whenever a property created by this manager
- changes its enum names, passing a pointer to the \a property and
- the new \a names as parameters.
- \sa setEnumNames()
- */
- /*!
- \fn void QtEnumPropertyManager::enumIconsChanged(QtProperty *property, const QMap<int, QIcon> &icons)
- This signal is emitted whenever a property created by this manager
- changes its enum icons, passing a pointer to the \a property and
- the new mapping of values to \a icons as parameters.
- \sa setEnumIcons()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtEnumPropertyManager::QtEnumPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtEnumPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtEnumPropertyManager::~QtEnumPropertyManager()
- {
- clear();
- }
- /*!
- Returns the given \a property's value which is an index in the
- list returned by enumNames()
- If the given property is not managed by this manager, this
- function returns -1.
- \sa enumNames(), setValue()
- */
- int QtEnumPropertyManager::value(const QtProperty *property) const
- {
- return getValue<int>(d_ptr->m_values, property, -1);
- }
- /*!
- Returns the given \a property's list of enum names.
- \sa value(), setEnumNames()
- */
- QStringList QtEnumPropertyManager::enumNames(const QtProperty *property) const
- {
- return getData<QStringList>(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumNames, property, QStringList());
- }
- /*!
- Returns the given \a property's map of enum values to their icons.
- \sa value(), setEnumIcons()
- */
- QMap<int, QIcon> QtEnumPropertyManager::enumIcons(const QtProperty *property) const
- {
- return getData<QMap<int, QIcon> >(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumIcons, property, QMap<int, QIcon>());
- }
- /*!
- \reimp
- */
- QString QtEnumPropertyManager::valueText(const QtProperty *property) const
- {
- const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QtEnumPropertyManagerPrivate::Data &data = it.value();
- const int v = data.val;
- if (v >= 0 && v < data.enumNames.count())
- return data.enumNames.at(v);
- return QString();
- }
- /*!
- \reimp
- */
- QIcon QtEnumPropertyManager::valueIcon(const QtProperty *property) const
- {
- const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QIcon();
- const QtEnumPropertyManagerPrivate::Data &data = it.value();
- const int v = data.val;
- return data.enumIcons.value(v);
- }
- /*!
- \fn void QtEnumPropertyManager::setValue(QtProperty *property, int value)
- Sets the value of the given \a property to \a value.
- The specified \a value must be less than the size of the given \a
- property's enumNames() list, and larger than (or equal to) 0.
- \sa value(), valueChanged()
- */
- void QtEnumPropertyManager::setValue(QtProperty *property, int val)
- {
- const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtEnumPropertyManagerPrivate::Data data = it.value();
- if (val >= data.enumNames.count())
- return;
- if (val < 0 && data.enumNames.count() > 0)
- return;
- if (val < 0)
- val = -1;
- if (data.val == val)
- return;
- data.val = val;
- it.value() = data;
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the given \a property's list of enum names to \a
- enumNames. The \a property's current value is reset to 0
- indicating the first item of the list.
- If the specified \a enumNames list is empty, the \a property's
- current value is set to -1.
- \sa enumNames(), enumNamesChanged()
- */
- void QtEnumPropertyManager::setEnumNames(QtProperty *property, const QStringList &enumNames)
- {
- const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtEnumPropertyManagerPrivate::Data data = it.value();
- if (data.enumNames == enumNames)
- return;
- data.enumNames = enumNames;
- data.val = -1;
- if (enumNames.count() > 0)
- data.val = 0;
- it.value() = data;
- emit enumNamesChanged(property, data.enumNames);
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the given \a property's map of enum values to their icons to \a
- enumIcons.
- Each enum value can have associated icon. This association is represented with passed \a enumIcons map.
- \sa enumNames(), enumNamesChanged()
- */
- void QtEnumPropertyManager::setEnumIcons(QtProperty *property, const QMap<int, QIcon> &enumIcons)
- {
- const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- it.value().enumIcons = enumIcons;
- emit enumIconsChanged(property, it.value().enumIcons);
- emit propertyChanged(property);
- }
- /*!
- \reimp
- */
- void QtEnumPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtEnumPropertyManagerPrivate::Data();
- }
- /*!
- \reimp
- */
- void QtEnumPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtFlagPropertyManager
- class QtFlagPropertyManagerPrivate
- {
- QtFlagPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtFlagPropertyManager)
- public:
- void slotBoolChanged(QtProperty *property, bool value);
- void slotPropertyDestroyed(QtProperty *property);
- struct Data
- {
- int val{-1};
- QStringList flagNames;
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtBoolPropertyManager *m_boolPropertyManager;
- QMap<const QtProperty *, QList<QtProperty *> > m_propertyToFlags;
- QMap<const QtProperty *, QtProperty *> m_flagToProperty;
- };
- void QtFlagPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
- {
- QtProperty *prop = m_flagToProperty.value(property, 0);
- if (prop == 0)
- return;
- const auto pfit = m_propertyToFlags.constFind(prop);
- if (pfit == m_propertyToFlags.constEnd())
- return;
- int level = 0;
- for (QtProperty *p : pfit.value()) {
- if (p == property) {
- int v = m_values[prop].val;
- if (value) {
- v |= (1 << level);
- } else {
- v &= ~(1 << level);
- }
- q_ptr->setValue(prop, v);
- return;
- }
- level++;
- }
- }
- void QtFlagPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- QtProperty *flagProperty = m_flagToProperty.value(property, 0);
- if (flagProperty == 0)
- return;
- m_propertyToFlags[flagProperty].replace(m_propertyToFlags[flagProperty].indexOf(property), 0);
- m_flagToProperty.remove(property);
- }
- /*!
- \class QtFlagPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtFlagPropertyManager provides and manages flag properties.
- Each flag property has an associated list of flag names which can
- be retrieved using the flagNames() function, and set using the
- corresponding setFlagNames() function.
- The flag manager provides properties with nested boolean
- subproperties representing each flag, i.e. a flag property's value
- is the binary combination of the subproperties' values. A
- property's value can be retrieved and set using the value() and
- setValue() slots respectively. The combination of flags is represented
- by single int value - that's why it's possible to store up to
- 32 independent flags in one flag property.
- The subproperties are created by a QtBoolPropertyManager object. This
- manager can be retrieved using the subBoolPropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- In addition, QtFlagPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the flagNamesChanged() signal which is emitted
- whenever the list of flag names is altered.
- \sa QtAbstractPropertyManager, QtBoolPropertyManager
- */
- /*!
- \fn void QtFlagPropertyManager::valueChanged(QtProperty *property, int value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtFlagPropertyManager::flagNamesChanged(QtProperty *property, const QStringList &names)
- This signal is emitted whenever a property created by this manager
- changes its flag names, passing a pointer to the \a property and the
- new \a names as parameters.
- \sa setFlagNames()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtFlagPropertyManager::QtFlagPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtFlagPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
- connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*,bool)),
- this, SLOT(slotBoolChanged(QtProperty*,bool)));
- connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtFlagPropertyManager::~QtFlagPropertyManager()
- {
- clear();
- }
- /*!
- Returns the manager that produces the nested boolean subproperties
- representing each flag.
- In order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtBoolPropertyManager *QtFlagPropertyManager::subBoolPropertyManager() const
- {
- return d_ptr->m_boolPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns 0.
- \sa flagNames(), setValue()
- */
- int QtFlagPropertyManager::value(const QtProperty *property) const
- {
- return getValue<int>(d_ptr->m_values, property, 0);
- }
- /*!
- Returns the given \a property's list of flag names.
- \sa value(), setFlagNames()
- */
- QStringList QtFlagPropertyManager::flagNames(const QtProperty *property) const
- {
- return getData<QStringList>(d_ptr->m_values, &QtFlagPropertyManagerPrivate::Data::flagNames, property, QStringList());
- }
- /*!
- \reimp
- */
- QString QtFlagPropertyManager::valueText(const QtProperty *property) const
- {
- const QtFlagPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QtFlagPropertyManagerPrivate::Data &data = it.value();
- QString str;
- int level = 0;
- const QChar bar = QLatin1Char('|');
- const QStringList::const_iterator fncend = data.flagNames.constEnd();
- for (QStringList::const_iterator it = data.flagNames.constBegin(); it != fncend; ++it) {
- if (data.val & (1 << level)) {
- if (!str.isEmpty())
- str += bar;
- str += *it;
- }
- level++;
- }
- return str;
- }
- /*!
- \fn void QtFlagPropertyManager::setValue(QtProperty *property, int value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- The specified \a value must be less than the binary combination of
- the property's flagNames() list size (i.e. less than 2\sup n,
- where \c n is the size of the list) and larger than (or equal to)
- 0.
- \sa value(), valueChanged()
- */
- void QtFlagPropertyManager::setValue(QtProperty *property, int val)
- {
- const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtFlagPropertyManagerPrivate::Data data = it.value();
- if (data.val == val)
- return;
- if (val > (1 << data.flagNames.count()) - 1)
- return;
- if (val < 0)
- return;
- data.val = val;
- it.value() = data;
- const auto pfit = d_ptr->m_propertyToFlags.constFind(property);
- int level = 0;
- if (pfit != d_ptr->m_propertyToFlags.constEnd()) {
- for (QtProperty *prop : pfit.value()) {
- if (prop)
- d_ptr->m_boolPropertyManager->setValue(prop, val & (1 << level));
- level++;
- }
- }
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the given \a property's list of flag names to \a flagNames. The
- property's current value is reset to 0 indicating the first item
- of the list.
- \sa flagNames(), flagNamesChanged()
- */
- void QtFlagPropertyManager::setFlagNames(QtProperty *property, const QStringList &flagNames)
- {
- const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtFlagPropertyManagerPrivate::Data data = it.value();
- if (data.flagNames == flagNames)
- return;
- data.flagNames = flagNames;
- data.val = 0;
- it.value() = data;
- const auto pfit = d_ptr->m_propertyToFlags.find(property);
- if (pfit != d_ptr->m_propertyToFlags.end()) {
- for (QtProperty *prop : qAsConst(pfit.value())) {
- if (prop) {
- delete prop;
- d_ptr->m_flagToProperty.remove(prop);
- }
- }
- pfit.value().clear();
- }
- for (const QString &flagName : flagNames) {
- QtProperty *prop = d_ptr->m_boolPropertyManager->addProperty();
- prop->setPropertyName(flagName);
- property->addSubProperty(prop);
- d_ptr->m_propertyToFlags[property].append(prop);
- d_ptr->m_flagToProperty[prop] = property;
- }
- emit flagNamesChanged(property, data.flagNames);
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- \reimp
- */
- void QtFlagPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtFlagPropertyManagerPrivate::Data();
- d_ptr->m_propertyToFlags[property] = QList<QtProperty *>();
- }
- /*!
- \reimp
- */
- void QtFlagPropertyManager::uninitializeProperty(QtProperty *property)
- {
- const auto it = d_ptr->m_propertyToFlags.find(property);
- if (it != d_ptr->m_propertyToFlags.end()) {
- for (QtProperty *prop : qAsConst(it.value())) {
- if (prop) {
- d_ptr->m_flagToProperty.remove(prop);
- delete prop;
- }
- }
- }
- d_ptr->m_propertyToFlags.erase(it);
- d_ptr->m_values.remove(property);
- }
- // QtSizePolicyPropertyManager
- class QtSizePolicyPropertyManagerPrivate
- {
- QtSizePolicyPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtSizePolicyPropertyManager)
- public:
- QtSizePolicyPropertyManagerPrivate();
- void slotIntChanged(QtProperty *property, int value);
- void slotEnumChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- typedef QMap<const QtProperty *, QSizePolicy> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QtEnumPropertyManager *m_enumPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToHPolicy;
- QMap<const QtProperty *, QtProperty *> m_propertyToVPolicy;
- QMap<const QtProperty *, QtProperty *> m_propertyToHStretch;
- QMap<const QtProperty *, QtProperty *> m_propertyToVStretch;
- QMap<const QtProperty *, QtProperty *> m_hPolicyToProperty;
- QMap<const QtProperty *, QtProperty *> m_vPolicyToProperty;
- QMap<const QtProperty *, QtProperty *> m_hStretchToProperty;
- QMap<const QtProperty *, QtProperty *> m_vStretchToProperty;
- };
- QtSizePolicyPropertyManagerPrivate::QtSizePolicyPropertyManagerPrivate()
- {
- }
- void QtSizePolicyPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_hStretchToProperty.value(property, 0)) {
- QSizePolicy sp = m_values[prop];
- sp.setHorizontalStretch(value);
- q_ptr->setValue(prop, sp);
- } else if (QtProperty *prop = m_vStretchToProperty.value(property, 0)) {
- QSizePolicy sp = m_values[prop];
- sp.setVerticalStretch(value);
- q_ptr->setValue(prop, sp);
- }
- }
- void QtSizePolicyPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_hPolicyToProperty.value(property, 0)) {
- QSizePolicy sp = m_values[prop];
- sp.setHorizontalPolicy(metaEnumProvider()->indexToSizePolicy(value));
- q_ptr->setValue(prop, sp);
- } else if (QtProperty *prop = m_vPolicyToProperty.value(property, 0)) {
- QSizePolicy sp = m_values[prop];
- sp.setVerticalPolicy(metaEnumProvider()->indexToSizePolicy(value));
- q_ptr->setValue(prop, sp);
- }
- }
- void QtSizePolicyPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_hStretchToProperty.value(property, 0)) {
- m_propertyToHStretch[pointProp] = 0;
- m_hStretchToProperty.remove(property);
- } else if (QtProperty *pointProp = m_vStretchToProperty.value(property, 0)) {
- m_propertyToVStretch[pointProp] = 0;
- m_vStretchToProperty.remove(property);
- } else if (QtProperty *pointProp = m_hPolicyToProperty.value(property, 0)) {
- m_propertyToHPolicy[pointProp] = 0;
- m_hPolicyToProperty.remove(property);
- } else if (QtProperty *pointProp = m_vPolicyToProperty.value(property, 0)) {
- m_propertyToVPolicy[pointProp] = 0;
- m_vPolicyToProperty.remove(property);
- }
- }
- /*!
- \class QtSizePolicyPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtSizePolicyPropertyManager provides and manages QSizePolicy properties.
- A size policy property has nested \e horizontalPolicy, \e
- verticalPolicy, \e horizontalStretch and \e verticalStretch
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by QtIntPropertyManager and QtEnumPropertyManager
- objects. These managers can be retrieved using the subIntPropertyManager()
- and subEnumPropertyManager() functions respectively. In order to provide
- editing widgets for the subproperties in a property browser widget,
- these managers must be associated with editor factories.
- In addition, QtSizePolicyPropertyManager provides the valueChanged()
- signal which is emitted whenever a property created by this
- manager changes.
- \sa QtAbstractPropertyManager, QtIntPropertyManager, QtEnumPropertyManager
- */
- /*!
- \fn void QtSizePolicyPropertyManager::valueChanged(QtProperty *property, const QSizePolicy &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtSizePolicyPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
- this, SLOT(slotIntChanged(QtProperty*,int)));
- d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
- connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
- this, SLOT(slotEnumChanged(QtProperty*,int)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtSizePolicyPropertyManager::~QtSizePolicyPropertyManager()
- {
- clear();
- }
- /*!
- Returns the manager that creates the nested \e horizontalStretch
- and \e verticalStretch subproperties.
- In order to provide editing widgets for the mentioned subproperties
- in a property browser widget, this manager must be associated with
- an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtSizePolicyPropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the manager that creates the nested \e horizontalPolicy
- and \e verticalPolicy subproperties.
- In order to provide editing widgets for the mentioned subproperties
- in a property browser widget, this manager must be associated with
- an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtEnumPropertyManager *QtSizePolicyPropertyManager::subEnumPropertyManager() const
- {
- return d_ptr->m_enumPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns the default size policy.
- \sa setValue()
- */
- QSizePolicy QtSizePolicyPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QSizePolicy());
- }
- /*!
- \reimp
- */
- QString QtSizePolicyPropertyManager::valueText(const QtProperty *property) const
- {
- const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QSizePolicy sp = it.value();
- const QtMetaEnumProvider *mep = metaEnumProvider();
- const int hIndex = mep->sizePolicyToIndex(sp.horizontalPolicy());
- const int vIndex = mep->sizePolicyToIndex(sp.verticalPolicy());
- //! Unknown size policy on reading invalid uic3 files
- const QString hPolicy = hIndex != -1 ? mep->policyEnumNames().at(hIndex) : tr("<Invalid>");
- const QString vPolicy = vIndex != -1 ? mep->policyEnumNames().at(vIndex) : tr("<Invalid>");
- const QString str = tr("[%1, %2, %3, %4]").arg(hPolicy, vPolicy).arg(sp.horizontalStretch()).arg(sp.verticalStretch());
- return str;
- }
- /*!
- \fn void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &val)
- {
- const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- if (it.value() == val)
- return;
- it.value() = val;
- d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToHPolicy[property],
- metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
- d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToVPolicy[property],
- metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToHStretch[property],
- val.horizontalStretch());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToVStretch[property],
- val.verticalStretch());
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \reimp
- */
- void QtSizePolicyPropertyManager::initializeProperty(QtProperty *property)
- {
- QSizePolicy val;
- d_ptr->m_values[property] = val;
- QtProperty *hPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
- hPolicyProp->setPropertyName(tr("Horizontal Policy"));
- d_ptr->m_enumPropertyManager->setEnumNames(hPolicyProp, metaEnumProvider()->policyEnumNames());
- d_ptr->m_enumPropertyManager->setValue(hPolicyProp,
- metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
- d_ptr->m_propertyToHPolicy[property] = hPolicyProp;
- d_ptr->m_hPolicyToProperty[hPolicyProp] = property;
- property->addSubProperty(hPolicyProp);
- QtProperty *vPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
- vPolicyProp->setPropertyName(tr("Vertical Policy"));
- d_ptr->m_enumPropertyManager->setEnumNames(vPolicyProp, metaEnumProvider()->policyEnumNames());
- d_ptr->m_enumPropertyManager->setValue(vPolicyProp,
- metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
- d_ptr->m_propertyToVPolicy[property] = vPolicyProp;
- d_ptr->m_vPolicyToProperty[vPolicyProp] = property;
- property->addSubProperty(vPolicyProp);
- QtProperty *hStretchProp = d_ptr->m_intPropertyManager->addProperty();
- hStretchProp->setPropertyName(tr("Horizontal Stretch"));
- d_ptr->m_intPropertyManager->setValue(hStretchProp, val.horizontalStretch());
- d_ptr->m_intPropertyManager->setRange(hStretchProp, 0, 0xff);
- d_ptr->m_propertyToHStretch[property] = hStretchProp;
- d_ptr->m_hStretchToProperty[hStretchProp] = property;
- property->addSubProperty(hStretchProp);
- QtProperty *vStretchProp = d_ptr->m_intPropertyManager->addProperty();
- vStretchProp->setPropertyName(tr("Vertical Stretch"));
- d_ptr->m_intPropertyManager->setValue(vStretchProp, val.verticalStretch());
- d_ptr->m_intPropertyManager->setRange(vStretchProp, 0, 0xff);
- d_ptr->m_propertyToVStretch[property] = vStretchProp;
- d_ptr->m_vStretchToProperty[vStretchProp] = property;
- property->addSubProperty(vStretchProp);
- }
- /*!
- \reimp
- */
- void QtSizePolicyPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *hPolicyProp = d_ptr->m_propertyToHPolicy[property];
- if (hPolicyProp) {
- d_ptr->m_hPolicyToProperty.remove(hPolicyProp);
- delete hPolicyProp;
- }
- d_ptr->m_propertyToHPolicy.remove(property);
- QtProperty *vPolicyProp = d_ptr->m_propertyToVPolicy[property];
- if (vPolicyProp) {
- d_ptr->m_vPolicyToProperty.remove(vPolicyProp);
- delete vPolicyProp;
- }
- d_ptr->m_propertyToVPolicy.remove(property);
- QtProperty *hStretchProp = d_ptr->m_propertyToHStretch[property];
- if (hStretchProp) {
- d_ptr->m_hStretchToProperty.remove(hStretchProp);
- delete hStretchProp;
- }
- d_ptr->m_propertyToHStretch.remove(property);
- QtProperty *vStretchProp = d_ptr->m_propertyToVStretch[property];
- if (vStretchProp) {
- d_ptr->m_vStretchToProperty.remove(vStretchProp);
- delete vStretchProp;
- }
- d_ptr->m_propertyToVStretch.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtFontPropertyManager:
- // QtFontPropertyManagerPrivate has a mechanism for reacting
- // to QApplication::fontDatabaseChanged() [4.5], which is emitted
- // when someone loads an application font. The signals are compressed
- // using a timer with interval 0, which then causes the family
- // enumeration manager to re-set its strings and index values
- // for each property.
- Q_GLOBAL_STATIC(QFontDatabase, fontDatabase)
- class QtFontPropertyManagerPrivate
- {
- QtFontPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtFontPropertyManager)
- public:
- QtFontPropertyManagerPrivate();
- void slotIntChanged(QtProperty *property, int value);
- void slotEnumChanged(QtProperty *property, int value);
- void slotBoolChanged(QtProperty *property, bool value);
- void slotPropertyDestroyed(QtProperty *property);
- void slotFontDatabaseChanged();
- void slotFontDatabaseDelayedChange();
- QStringList m_familyNames;
- typedef QMap<const QtProperty *, QFont> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QtEnumPropertyManager *m_enumPropertyManager;
- QtBoolPropertyManager *m_boolPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToFamily;
- QMap<const QtProperty *, QtProperty *> m_propertyToPointSize;
- QMap<const QtProperty *, QtProperty *> m_propertyToBold;
- QMap<const QtProperty *, QtProperty *> m_propertyToItalic;
- QMap<const QtProperty *, QtProperty *> m_propertyToUnderline;
- QMap<const QtProperty *, QtProperty *> m_propertyToStrikeOut;
- QMap<const QtProperty *, QtProperty *> m_propertyToKerning;
- QMap<const QtProperty *, QtProperty *> m_familyToProperty;
- QMap<const QtProperty *, QtProperty *> m_pointSizeToProperty;
- QMap<const QtProperty *, QtProperty *> m_boldToProperty;
- QMap<const QtProperty *, QtProperty *> m_italicToProperty;
- QMap<const QtProperty *, QtProperty *> m_underlineToProperty;
- QMap<const QtProperty *, QtProperty *> m_strikeOutToProperty;
- QMap<const QtProperty *, QtProperty *> m_kerningToProperty;
- bool m_settingValue;
- QTimer *m_fontDatabaseChangeTimer;
- };
- QtFontPropertyManagerPrivate::QtFontPropertyManagerPrivate() :
- m_settingValue(false),
- m_fontDatabaseChangeTimer(0)
- {
- }
- void QtFontPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (m_settingValue)
- return;
- if (QtProperty *prop = m_pointSizeToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setPointSize(value);
- q_ptr->setValue(prop, f);
- }
- }
- void QtFontPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
- {
- if (m_settingValue)
- return;
- if (QtProperty *prop = m_familyToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setFamily(m_familyNames.at(value));
- q_ptr->setValue(prop, f);
- }
- }
- void QtFontPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
- {
- if (m_settingValue)
- return;
- if (QtProperty *prop = m_boldToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setBold(value);
- q_ptr->setValue(prop, f);
- } else if (QtProperty *prop = m_italicToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setItalic(value);
- q_ptr->setValue(prop, f);
- } else if (QtProperty *prop = m_underlineToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setUnderline(value);
- q_ptr->setValue(prop, f);
- } else if (QtProperty *prop = m_strikeOutToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setStrikeOut(value);
- q_ptr->setValue(prop, f);
- } else if (QtProperty *prop = m_kerningToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setKerning(value);
- q_ptr->setValue(prop, f);
- }
- }
- void QtFontPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_pointSizeToProperty.value(property, 0)) {
- m_propertyToPointSize[pointProp] = 0;
- m_pointSizeToProperty.remove(property);
- } else if (QtProperty *pointProp = m_familyToProperty.value(property, 0)) {
- m_propertyToFamily[pointProp] = 0;
- m_familyToProperty.remove(property);
- } else if (QtProperty *pointProp = m_boldToProperty.value(property, 0)) {
- m_propertyToBold[pointProp] = 0;
- m_boldToProperty.remove(property);
- } else if (QtProperty *pointProp = m_italicToProperty.value(property, 0)) {
- m_propertyToItalic[pointProp] = 0;
- m_italicToProperty.remove(property);
- } else if (QtProperty *pointProp = m_underlineToProperty.value(property, 0)) {
- m_propertyToUnderline[pointProp] = 0;
- m_underlineToProperty.remove(property);
- } else if (QtProperty *pointProp = m_strikeOutToProperty.value(property, 0)) {
- m_propertyToStrikeOut[pointProp] = 0;
- m_strikeOutToProperty.remove(property);
- } else if (QtProperty *pointProp = m_kerningToProperty.value(property, 0)) {
- m_propertyToKerning[pointProp] = 0;
- m_kerningToProperty.remove(property);
- }
- }
- void QtFontPropertyManagerPrivate::slotFontDatabaseChanged()
- {
- if (!m_fontDatabaseChangeTimer) {
- m_fontDatabaseChangeTimer = new QTimer(q_ptr);
- m_fontDatabaseChangeTimer->setInterval(0);
- m_fontDatabaseChangeTimer->setSingleShot(true);
- QObject::connect(m_fontDatabaseChangeTimer, SIGNAL(timeout()), q_ptr, SLOT(slotFontDatabaseDelayedChange()));
- }
- if (!m_fontDatabaseChangeTimer->isActive())
- m_fontDatabaseChangeTimer->start();
- }
- void QtFontPropertyManagerPrivate::slotFontDatabaseDelayedChange()
- {
- typedef QMap<const QtProperty *, QtProperty *> PropertyPropertyMap;
- // rescan available font names
- const QStringList oldFamilies = m_familyNames;
- m_familyNames = fontDatabase()->families();
- // Adapt all existing properties
- if (!m_propertyToFamily.empty()) {
- PropertyPropertyMap::const_iterator cend = m_propertyToFamily.constEnd();
- for (PropertyPropertyMap::const_iterator it = m_propertyToFamily.constBegin(); it != cend; ++it) {
- QtProperty *familyProp = it.value();
- const int oldIdx = m_enumPropertyManager->value(familyProp);
- int newIdx = m_familyNames.indexOf(oldFamilies.at(oldIdx));
- if (newIdx < 0)
- newIdx = 0;
- m_enumPropertyManager->setEnumNames(familyProp, m_familyNames);
- m_enumPropertyManager->setValue(familyProp, newIdx);
- }
- }
- }
- /*!
- \class QtFontPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtFontPropertyManager provides and manages QFont properties.
- A font property has nested \e family, \e pointSize, \e bold, \e
- italic, \e underline, \e strikeOut and \e kerning subproperties. The top-level
- property's value can be retrieved using the value() function, and
- set using the setValue() slot.
- The subproperties are created by QtIntPropertyManager, QtEnumPropertyManager and
- QtBoolPropertyManager objects. These managers can be retrieved using the
- corresponding subIntPropertyManager(), subEnumPropertyManager() and
- subBoolPropertyManager() functions. In order to provide editing widgets
- for the subproperties in a property browser widget, these managers
- must be associated with editor factories.
- In addition, QtFontPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager, QtEnumPropertyManager, QtIntPropertyManager, QtBoolPropertyManager
- */
- /*!
- \fn void QtFontPropertyManager::valueChanged(QtProperty *property, const QFont &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtFontPropertyManager::QtFontPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtFontPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- QObject::connect(qApp, SIGNAL(fontDatabaseChanged()), this, SLOT(slotFontDatabaseChanged()));
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
- this, SLOT(slotIntChanged(QtProperty*,int)));
- d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
- connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
- this, SLOT(slotEnumChanged(QtProperty*,int)));
- d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
- connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*,bool)),
- this, SLOT(slotBoolChanged(QtProperty*,bool)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtFontPropertyManager::~QtFontPropertyManager()
- {
- clear();
- }
- /*!
- Returns the manager that creates the \e pointSize subproperty.
- In order to provide editing widgets for the \e pointSize property
- in a property browser widget, this manager must be associated
- with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtFontPropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the manager that create the \e family subproperty.
- In order to provide editing widgets for the \e family property
- in a property browser widget, this manager must be associated
- with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtEnumPropertyManager *QtFontPropertyManager::subEnumPropertyManager() const
- {
- return d_ptr->m_enumPropertyManager;
- }
- /*!
- Returns the manager that creates the \e bold, \e italic, \e underline,
- \e strikeOut and \e kerning subproperties.
- In order to provide editing widgets for the mentioned properties
- in a property browser widget, this manager must be associated with
- an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtBoolPropertyManager *QtFontPropertyManager::subBoolPropertyManager() const
- {
- return d_ptr->m_boolPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns a font object that uses the application's default
- font.
- \sa setValue()
- */
- QFont QtFontPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QFont());
- }
- /*!
- \reimp
- */
- QString QtFontPropertyManager::valueText(const QtProperty *property) const
- {
- const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return QtPropertyBrowserUtils::fontValueText(it.value());
- }
- /*!
- \reimp
- */
- QIcon QtFontPropertyManager::valueIcon(const QtProperty *property) const
- {
- const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QIcon();
- return QtPropertyBrowserUtils::fontValueIcon(it.value());
- }
- /*!
- \fn void QtFontPropertyManager::setValue(QtProperty *property, const QFont &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtFontPropertyManager::setValue(QtProperty *property, const QFont &val)
- {
- const QtFontPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- const QFont oldVal = it.value();
- if (oldVal == val && oldVal.resolve() == val.resolve())
- return;
- it.value() = val;
- int idx = d_ptr->m_familyNames.indexOf(val.family());
- if (idx == -1)
- idx = 0;
- bool settingValue = d_ptr->m_settingValue;
- d_ptr->m_settingValue = true;
- d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToFamily[property], idx);
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToPointSize[property], val.pointSize());
- d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToBold[property], val.bold());
- d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToItalic[property], val.italic());
- d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToUnderline[property], val.underline());
- d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToStrikeOut[property], val.strikeOut());
- d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToKerning[property], val.kerning());
- d_ptr->m_settingValue = settingValue;
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \reimp
- */
- void QtFontPropertyManager::initializeProperty(QtProperty *property)
- {
- QFont val;
- d_ptr->m_values[property] = val;
- QtProperty *familyProp = d_ptr->m_enumPropertyManager->addProperty();
- familyProp->setPropertyName(tr("Family"));
- if (d_ptr->m_familyNames.empty())
- d_ptr->m_familyNames = fontDatabase()->families();
- d_ptr->m_enumPropertyManager->setEnumNames(familyProp, d_ptr->m_familyNames);
- int idx = d_ptr->m_familyNames.indexOf(val.family());
- if (idx == -1)
- idx = 0;
- d_ptr->m_enumPropertyManager->setValue(familyProp, idx);
- d_ptr->m_propertyToFamily[property] = familyProp;
- d_ptr->m_familyToProperty[familyProp] = property;
- property->addSubProperty(familyProp);
- QtProperty *pointSizeProp = d_ptr->m_intPropertyManager->addProperty();
- pointSizeProp->setPropertyName(tr("Point Size"));
- d_ptr->m_intPropertyManager->setValue(pointSizeProp, val.pointSize());
- d_ptr->m_intPropertyManager->setMinimum(pointSizeProp, 1);
- d_ptr->m_propertyToPointSize[property] = pointSizeProp;
- d_ptr->m_pointSizeToProperty[pointSizeProp] = property;
- property->addSubProperty(pointSizeProp);
- QtProperty *boldProp = d_ptr->m_boolPropertyManager->addProperty();
- boldProp->setPropertyName(tr("Bold"));
- d_ptr->m_boolPropertyManager->setValue(boldProp, val.bold());
- d_ptr->m_propertyToBold[property] = boldProp;
- d_ptr->m_boldToProperty[boldProp] = property;
- property->addSubProperty(boldProp);
- QtProperty *italicProp = d_ptr->m_boolPropertyManager->addProperty();
- italicProp->setPropertyName(tr("Italic"));
- d_ptr->m_boolPropertyManager->setValue(italicProp, val.italic());
- d_ptr->m_propertyToItalic[property] = italicProp;
- d_ptr->m_italicToProperty[italicProp] = property;
- property->addSubProperty(italicProp);
- QtProperty *underlineProp = d_ptr->m_boolPropertyManager->addProperty();
- underlineProp->setPropertyName(tr("Underline"));
- d_ptr->m_boolPropertyManager->setValue(underlineProp, val.underline());
- d_ptr->m_propertyToUnderline[property] = underlineProp;
- d_ptr->m_underlineToProperty[underlineProp] = property;
- property->addSubProperty(underlineProp);
- QtProperty *strikeOutProp = d_ptr->m_boolPropertyManager->addProperty();
- strikeOutProp->setPropertyName(tr("Strikeout"));
- d_ptr->m_boolPropertyManager->setValue(strikeOutProp, val.strikeOut());
- d_ptr->m_propertyToStrikeOut[property] = strikeOutProp;
- d_ptr->m_strikeOutToProperty[strikeOutProp] = property;
- property->addSubProperty(strikeOutProp);
- QtProperty *kerningProp = d_ptr->m_boolPropertyManager->addProperty();
- kerningProp->setPropertyName(tr("Kerning"));
- d_ptr->m_boolPropertyManager->setValue(kerningProp, val.kerning());
- d_ptr->m_propertyToKerning[property] = kerningProp;
- d_ptr->m_kerningToProperty[kerningProp] = property;
- property->addSubProperty(kerningProp);
- }
- /*!
- \reimp
- */
- void QtFontPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *familyProp = d_ptr->m_propertyToFamily[property];
- if (familyProp) {
- d_ptr->m_familyToProperty.remove(familyProp);
- delete familyProp;
- }
- d_ptr->m_propertyToFamily.remove(property);
- QtProperty *pointSizeProp = d_ptr->m_propertyToPointSize[property];
- if (pointSizeProp) {
- d_ptr->m_pointSizeToProperty.remove(pointSizeProp);
- delete pointSizeProp;
- }
- d_ptr->m_propertyToPointSize.remove(property);
- QtProperty *boldProp = d_ptr->m_propertyToBold[property];
- if (boldProp) {
- d_ptr->m_boldToProperty.remove(boldProp);
- delete boldProp;
- }
- d_ptr->m_propertyToBold.remove(property);
- QtProperty *italicProp = d_ptr->m_propertyToItalic[property];
- if (italicProp) {
- d_ptr->m_italicToProperty.remove(italicProp);
- delete italicProp;
- }
- d_ptr->m_propertyToItalic.remove(property);
- QtProperty *underlineProp = d_ptr->m_propertyToUnderline[property];
- if (underlineProp) {
- d_ptr->m_underlineToProperty.remove(underlineProp);
- delete underlineProp;
- }
- d_ptr->m_propertyToUnderline.remove(property);
- QtProperty *strikeOutProp = d_ptr->m_propertyToStrikeOut[property];
- if (strikeOutProp) {
- d_ptr->m_strikeOutToProperty.remove(strikeOutProp);
- delete strikeOutProp;
- }
- d_ptr->m_propertyToStrikeOut.remove(property);
- QtProperty *kerningProp = d_ptr->m_propertyToKerning[property];
- if (kerningProp) {
- d_ptr->m_kerningToProperty.remove(kerningProp);
- delete kerningProp;
- }
- d_ptr->m_propertyToKerning.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtColorPropertyManager
- class QtColorPropertyManagerPrivate
- {
- QtColorPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtColorPropertyManager)
- public:
- void slotIntChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- typedef QMap<const QtProperty *, QColor> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToR;
- QMap<const QtProperty *, QtProperty *> m_propertyToG;
- QMap<const QtProperty *, QtProperty *> m_propertyToB;
- QMap<const QtProperty *, QtProperty *> m_propertyToA;
- QMap<const QtProperty *, QtProperty *> m_rToProperty;
- QMap<const QtProperty *, QtProperty *> m_gToProperty;
- QMap<const QtProperty *, QtProperty *> m_bToProperty;
- QMap<const QtProperty *, QtProperty *> m_aToProperty;
- };
- void QtColorPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_rToProperty.value(property, 0)) {
- QColor c = m_values[prop];
- c.setRed(value);
- q_ptr->setValue(prop, c);
- } else if (QtProperty *prop = m_gToProperty.value(property, 0)) {
- QColor c = m_values[prop];
- c.setGreen(value);
- q_ptr->setValue(prop, c);
- } else if (QtProperty *prop = m_bToProperty.value(property, 0)) {
- QColor c = m_values[prop];
- c.setBlue(value);
- q_ptr->setValue(prop, c);
- } else if (QtProperty *prop = m_aToProperty.value(property, 0)) {
- QColor c = m_values[prop];
- c.setAlpha(value);
- q_ptr->setValue(prop, c);
- }
- }
- void QtColorPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_rToProperty.value(property, 0)) {
- m_propertyToR[pointProp] = 0;
- m_rToProperty.remove(property);
- } else if (QtProperty *pointProp = m_gToProperty.value(property, 0)) {
- m_propertyToG[pointProp] = 0;
- m_gToProperty.remove(property);
- } else if (QtProperty *pointProp = m_bToProperty.value(property, 0)) {
- m_propertyToB[pointProp] = 0;
- m_bToProperty.remove(property);
- } else if (QtProperty *pointProp = m_aToProperty.value(property, 0)) {
- m_propertyToA[pointProp] = 0;
- m_aToProperty.remove(property);
- }
- }
- /*!
- \class QtColorPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtColorPropertyManager provides and manages QColor properties.
- A color property has nested \e red, \e green and \e blue
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by a QtIntPropertyManager object. This
- manager can be retrieved using the subIntPropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- In addition, QtColorPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager, QtAbstractPropertyBrowser, QtIntPropertyManager
- */
- /*!
- \fn void QtColorPropertyManager::valueChanged(QtProperty *property, const QColor &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtColorPropertyManager::QtColorPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtColorPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
- this, SLOT(slotIntChanged(QtProperty*,int)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
- this, SLOT(slotPropertyDestroyed(QtProperty*)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtColorPropertyManager::~QtColorPropertyManager()
- {
- clear();
- }
- /*!
- Returns the manager that produces the nested \e red, \e green and
- \e blue subproperties.
- In order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtColorPropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by \e this manager, this
- function returns an invalid color.
- \sa setValue()
- */
- QColor QtColorPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QColor());
- }
- /*!
- \reimp
- */
- QString QtColorPropertyManager::valueText(const QtProperty *property) const
- {
- const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return QtPropertyBrowserUtils::colorValueText(it.value());
- }
- /*!
- \reimp
- */
- QIcon QtColorPropertyManager::valueIcon(const QtProperty *property) const
- {
- const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QIcon();
- return QtPropertyBrowserUtils::brushValueIcon(QBrush(it.value()));
- }
- /*!
- \fn void QtColorPropertyManager::setValue(QtProperty *property, const QColor &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtColorPropertyManager::setValue(QtProperty *property, const QColor &val)
- {
- const QtColorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- if (it.value() == val)
- return;
- it.value() = val;
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToR[property], val.red());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToG[property], val.green());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToB[property], val.blue());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToA[property], val.alpha());
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \reimp
- */
- void QtColorPropertyManager::initializeProperty(QtProperty *property)
- {
- QColor val;
- d_ptr->m_values[property] = val;
- QtProperty *rProp = d_ptr->m_intPropertyManager->addProperty();
- rProp->setPropertyName(tr("Red"));
- d_ptr->m_intPropertyManager->setValue(rProp, val.red());
- d_ptr->m_intPropertyManager->setRange(rProp, 0, 0xFF);
- d_ptr->m_propertyToR[property] = rProp;
- d_ptr->m_rToProperty[rProp] = property;
- property->addSubProperty(rProp);
- QtProperty *gProp = d_ptr->m_intPropertyManager->addProperty();
- gProp->setPropertyName(tr("Green"));
- d_ptr->m_intPropertyManager->setValue(gProp, val.green());
- d_ptr->m_intPropertyManager->setRange(gProp, 0, 0xFF);
- d_ptr->m_propertyToG[property] = gProp;
- d_ptr->m_gToProperty[gProp] = property;
- property->addSubProperty(gProp);
- QtProperty *bProp = d_ptr->m_intPropertyManager->addProperty();
- bProp->setPropertyName(tr("Blue"));
- d_ptr->m_intPropertyManager->setValue(bProp, val.blue());
- d_ptr->m_intPropertyManager->setRange(bProp, 0, 0xFF);
- d_ptr->m_propertyToB[property] = bProp;
- d_ptr->m_bToProperty[bProp] = property;
- property->addSubProperty(bProp);
- QtProperty *aProp = d_ptr->m_intPropertyManager->addProperty();
- aProp->setPropertyName(tr("Alpha"));
- d_ptr->m_intPropertyManager->setValue(aProp, val.alpha());
- d_ptr->m_intPropertyManager->setRange(aProp, 0, 0xFF);
- d_ptr->m_propertyToA[property] = aProp;
- d_ptr->m_aToProperty[aProp] = property;
- property->addSubProperty(aProp);
- }
- /*!
- \reimp
- */
- void QtColorPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *rProp = d_ptr->m_propertyToR[property];
- if (rProp) {
- d_ptr->m_rToProperty.remove(rProp);
- delete rProp;
- }
- d_ptr->m_propertyToR.remove(property);
- QtProperty *gProp = d_ptr->m_propertyToG[property];
- if (gProp) {
- d_ptr->m_gToProperty.remove(gProp);
- delete gProp;
- }
- d_ptr->m_propertyToG.remove(property);
- QtProperty *bProp = d_ptr->m_propertyToB[property];
- if (bProp) {
- d_ptr->m_bToProperty.remove(bProp);
- delete bProp;
- }
- d_ptr->m_propertyToB.remove(property);
- QtProperty *aProp = d_ptr->m_propertyToA[property];
- if (aProp) {
- d_ptr->m_aToProperty.remove(aProp);
- delete aProp;
- }
- d_ptr->m_propertyToA.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtCursorPropertyManager
- // Make sure icons are removed as soon as QApplication is destroyed, otherwise,
- // handles are leaked on X11.
- static void clearCursorDatabase();
- namespace {
- struct CursorDatabase : public QtCursorDatabase
- {
- CursorDatabase()
- {
- qAddPostRoutine(clearCursorDatabase);
- }
- };
- }
- Q_GLOBAL_STATIC(QtCursorDatabase, cursorDatabase)
- static void clearCursorDatabase()
- {
- cursorDatabase()->clear();
- }
- class QtCursorPropertyManagerPrivate
- {
- QtCursorPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtCursorPropertyManager)
- public:
- typedef QMap<const QtProperty *, QCursor> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*!
- \class QtCursorPropertyManager
- \internal
- \inmodule QtDesigner
- \since 4.4
- \brief The QtCursorPropertyManager provides and manages QCursor properties.
- A cursor property has a current value which can be
- retrieved using the value() function, and set using the setValue()
- slot. In addition, QtCursorPropertyManager provides the
- valueChanged() signal which is emitted whenever a property created
- by this manager changes.
- \sa QtAbstractPropertyManager
- */
- /*!
- \fn void QtCursorPropertyManager::valueChanged(QtProperty *property, const QCursor &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtCursorPropertyManager::QtCursorPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent), d_ptr(new QtCursorPropertyManagerPrivate)
- {
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtCursorPropertyManager::~QtCursorPropertyManager()
- {
- clear();
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns a default QCursor object.
- \sa setValue()
- */
- #ifndef QT_NO_CURSOR
- QCursor QtCursorPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QCursor());
- }
- #endif
- /*!
- \reimp
- */
- QString QtCursorPropertyManager::valueText(const QtProperty *property) const
- {
- const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return cursorDatabase()->cursorToShapeName(it.value());
- }
- /*!
- \reimp
- */
- QIcon QtCursorPropertyManager::valueIcon(const QtProperty *property) const
- {
- const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QIcon();
- return cursorDatabase()->cursorToShapeIcon(it.value());
- }
- /*!
- \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
- Sets the value of the given \a property to \a value.
- \sa value(), valueChanged()
- */
- void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
- {
- #ifndef QT_NO_CURSOR
- const QtCursorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- if (it.value().shape() == value.shape() && value.shape() != Qt::BitmapCursor)
- return;
- it.value() = value;
- emit propertyChanged(property);
- emit valueChanged(property, value);
- #endif
- }
- /*!
- \reimp
- */
- void QtCursorPropertyManager::initializeProperty(QtProperty *property)
- {
- #ifndef QT_NO_CURSOR
- d_ptr->m_values[property] = QCursor();
- #endif
- }
- /*!
- \reimp
- */
- void QtCursorPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- QT_END_NAMESPACE
- #include "moc_qtpropertymanager.cpp"
- #include "qtpropertymanager.moc"
|