qtpropertymanager.cpp 205 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the tools applications of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #include "qtpropertymanager.h"
  40. #include "qtpropertybrowserutils_p.h"
  41. #include <QtCore/QDateTime>
  42. #include <QtCore/QLocale>
  43. #include <QtCore/QMap>
  44. #include <QtCore/QTimer>
  45. #include <QtGui/QIcon>
  46. #include <QtCore/QMetaEnum>
  47. #include <QtGui/QFontDatabase>
  48. #include <QtWidgets/QStyleOption>
  49. #include <QtWidgets/QStyle>
  50. #include <QtWidgets/QApplication>
  51. #include <QtGui/QPainter>
  52. #include <QtWidgets/QLabel>
  53. #include <limits>
  54. #include <limits.h>
  55. #include <float.h>
  56. #if defined(Q_CC_MSVC)
  57. # pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
  58. #endif
  59. QT_BEGIN_NAMESPACE
  60. template <class PrivateData, class Value>
  61. static void setSimpleMinimumData(PrivateData *data, const Value &minVal)
  62. {
  63. data->minVal = minVal;
  64. if (data->maxVal < data->minVal)
  65. data->maxVal = data->minVal;
  66. if (data->val < data->minVal)
  67. data->val = data->minVal;
  68. }
  69. template <class PrivateData, class Value>
  70. static void setSimpleMaximumData(PrivateData *data, const Value &maxVal)
  71. {
  72. data->maxVal = maxVal;
  73. if (data->minVal > data->maxVal)
  74. data->minVal = data->maxVal;
  75. if (data->val > data->maxVal)
  76. data->val = data->maxVal;
  77. }
  78. template <class PrivateData, class Value>
  79. static void setSizeMinimumData(PrivateData *data, const Value &newMinVal)
  80. {
  81. data->minVal = newMinVal;
  82. if (data->maxVal.width() < data->minVal.width())
  83. data->maxVal.setWidth(data->minVal.width());
  84. if (data->maxVal.height() < data->minVal.height())
  85. data->maxVal.setHeight(data->minVal.height());
  86. if (data->val.width() < data->minVal.width())
  87. data->val.setWidth(data->minVal.width());
  88. if (data->val.height() < data->minVal.height())
  89. data->val.setHeight(data->minVal.height());
  90. }
  91. template <class PrivateData, class Value>
  92. static void setSizeMaximumData(PrivateData *data, const Value &newMaxVal)
  93. {
  94. data->maxVal = newMaxVal;
  95. if (data->minVal.width() > data->maxVal.width())
  96. data->minVal.setWidth(data->maxVal.width());
  97. if (data->minVal.height() > data->maxVal.height())
  98. data->minVal.setHeight(data->maxVal.height());
  99. if (data->val.width() > data->maxVal.width())
  100. data->val.setWidth(data->maxVal.width());
  101. if (data->val.height() > data->maxVal.height())
  102. data->val.setHeight(data->maxVal.height());
  103. }
  104. template <class SizeValue>
  105. static SizeValue qBoundSize(const SizeValue &minVal, const SizeValue &val, const SizeValue &maxVal)
  106. {
  107. SizeValue croppedVal = val;
  108. if (minVal.width() > val.width())
  109. croppedVal.setWidth(minVal.width());
  110. else if (maxVal.width() < val.width())
  111. croppedVal.setWidth(maxVal.width());
  112. if (minVal.height() > val.height())
  113. croppedVal.setHeight(minVal.height());
  114. else if (maxVal.height() < val.height())
  115. croppedVal.setHeight(maxVal.height());
  116. return croppedVal;
  117. }
  118. // Match the exact signature of qBound for VS 6.
  119. QSize qBound(QSize minVal, QSize val, QSize maxVal)
  120. {
  121. return qBoundSize(minVal, val, maxVal);
  122. }
  123. QSizeF qBound(QSizeF minVal, QSizeF val, QSizeF maxVal)
  124. {
  125. return qBoundSize(minVal, val, maxVal);
  126. }
  127. namespace {
  128. namespace {
  129. template <class Value>
  130. void orderBorders(Value &minVal, Value &maxVal)
  131. {
  132. if (minVal > maxVal)
  133. qSwap(minVal, maxVal);
  134. }
  135. template <class Value>
  136. static void orderSizeBorders(Value &minVal, Value &maxVal)
  137. {
  138. Value fromSize = minVal;
  139. Value toSize = maxVal;
  140. if (fromSize.width() > toSize.width()) {
  141. fromSize.setWidth(maxVal.width());
  142. toSize.setWidth(minVal.width());
  143. }
  144. if (fromSize.height() > toSize.height()) {
  145. fromSize.setHeight(maxVal.height());
  146. toSize.setHeight(minVal.height());
  147. }
  148. minVal = fromSize;
  149. maxVal = toSize;
  150. }
  151. void orderBorders(QSize &minVal, QSize &maxVal)
  152. {
  153. orderSizeBorders(minVal, maxVal);
  154. }
  155. void orderBorders(QSizeF &minVal, QSizeF &maxVal)
  156. {
  157. orderSizeBorders(minVal, maxVal);
  158. }
  159. }
  160. }
  161. ////////
  162. template <class Value, class PrivateData>
  163. static Value getData(const QMap<const QtProperty *, PrivateData> &propertyMap,
  164. Value PrivateData::*data,
  165. const QtProperty *property, const Value &defaultValue = Value())
  166. {
  167. const auto it = propertyMap.constFind(property);
  168. if (it == propertyMap.constEnd())
  169. return defaultValue;
  170. return it.value().*data;
  171. }
  172. template <class Value, class PrivateData>
  173. static Value getValue(const QMap<const QtProperty *, PrivateData> &propertyMap,
  174. const QtProperty *property, const Value &defaultValue = Value())
  175. {
  176. return getData<Value>(propertyMap, &PrivateData::val, property, defaultValue);
  177. }
  178. template <class Value, class PrivateData>
  179. static Value getMinimum(const QMap<const QtProperty *, PrivateData> &propertyMap,
  180. const QtProperty *property, const Value &defaultValue = Value())
  181. {
  182. return getData<Value>(propertyMap, &PrivateData::minVal, property, defaultValue);
  183. }
  184. template <class Value, class PrivateData>
  185. static Value getMaximum(const QMap<const QtProperty *, PrivateData> &propertyMap,
  186. const QtProperty *property, const Value &defaultValue = Value())
  187. {
  188. return getData<Value>(propertyMap, &PrivateData::maxVal, property, defaultValue);
  189. }
  190. template <class ValueChangeParameter, class Value, class PropertyManager>
  191. static void setSimpleValue(QMap<const QtProperty *, Value> &propertyMap,
  192. PropertyManager *manager,
  193. void (PropertyManager::*propertyChangedSignal)(QtProperty *),
  194. void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
  195. QtProperty *property, const Value &val)
  196. {
  197. const auto it = propertyMap.find(property);
  198. if (it == propertyMap.end())
  199. return;
  200. if (it.value() == val)
  201. return;
  202. it.value() = val;
  203. emit (manager->*propertyChangedSignal)(property);
  204. emit (manager->*valueChangedSignal)(property, val);
  205. }
  206. template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
  207. static void setValueInRange(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
  208. void (PropertyManager::*propertyChangedSignal)(QtProperty *),
  209. void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
  210. QtProperty *property, const Value &val,
  211. void (PropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, ValueChangeParameter))
  212. {
  213. const auto it = managerPrivate->m_values.find(property);
  214. if (it == managerPrivate->m_values.end())
  215. return;
  216. auto &data = it.value();
  217. if (data.val == val)
  218. return;
  219. const Value oldVal = data.val;
  220. data.val = qBound(data.minVal, val, data.maxVal);
  221. if (data.val == oldVal)
  222. return;
  223. if (setSubPropertyValue)
  224. (managerPrivate->*setSubPropertyValue)(property, data.val);
  225. emit (manager->*propertyChangedSignal)(property);
  226. emit (manager->*valueChangedSignal)(property, data.val);
  227. }
  228. template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
  229. static void setBorderValues(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
  230. void (PropertyManager::*propertyChangedSignal)(QtProperty *),
  231. void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
  232. void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
  233. QtProperty *property, const Value &minVal, const Value &maxVal,
  234. void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
  235. ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
  236. {
  237. const auto it = managerPrivate->m_values.find(property);
  238. if (it == managerPrivate->m_values.end())
  239. return;
  240. Value fromVal = minVal;
  241. Value toVal = maxVal;
  242. orderBorders(fromVal, toVal);
  243. auto &data = it.value();
  244. if (data.minVal == fromVal && data.maxVal == toVal)
  245. return;
  246. const Value oldVal = data.val;
  247. data.setMinimumValue(fromVal);
  248. data.setMaximumValue(toVal);
  249. emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
  250. if (setSubPropertyRange)
  251. (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
  252. if (data.val == oldVal)
  253. return;
  254. emit (manager->*propertyChangedSignal)(property);
  255. emit (manager->*valueChangedSignal)(property, data.val);
  256. }
  257. template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
  258. static void setBorderValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
  259. void (PropertyManager::*propertyChangedSignal)(QtProperty *),
  260. void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
  261. void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
  262. QtProperty *property,
  263. Value (PrivateData::*getRangeVal)() const,
  264. void (PrivateData::*setRangeVal)(ValueChangeParameter), const Value &borderVal,
  265. void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
  266. ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
  267. {
  268. const auto it = managerPrivate->m_values.find(property);
  269. if (it == managerPrivate->m_values.end())
  270. return;
  271. PrivateData &data = it.value();
  272. if ((data.*getRangeVal)() == borderVal)
  273. return;
  274. const Value oldVal = data.val;
  275. (data.*setRangeVal)(borderVal);
  276. emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
  277. if (setSubPropertyRange)
  278. (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
  279. if (data.val == oldVal)
  280. return;
  281. emit (manager->*propertyChangedSignal)(property);
  282. emit (manager->*valueChangedSignal)(property, data.val);
  283. }
  284. template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
  285. static void setMinimumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
  286. void (PropertyManager::*propertyChangedSignal)(QtProperty *),
  287. void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
  288. void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
  289. QtProperty *property, const Value &minVal)
  290. {
  291. void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
  292. ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
  293. setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
  294. propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
  295. property, &PropertyManagerPrivate::Data::minimumValue, &PropertyManagerPrivate::Data::setMinimumValue, minVal, setSubPropertyRange);
  296. }
  297. template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
  298. static void setMaximumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
  299. void (PropertyManager::*propertyChangedSignal)(QtProperty *),
  300. void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
  301. void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
  302. QtProperty *property, const Value &maxVal)
  303. {
  304. void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
  305. ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
  306. setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
  307. propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
  308. property, &PropertyManagerPrivate::Data::maximumValue, &PropertyManagerPrivate::Data::setMaximumValue, maxVal, setSubPropertyRange);
  309. }
  310. class QtMetaEnumWrapper : public QObject
  311. {
  312. Q_OBJECT
  313. Q_PROPERTY(QSizePolicy::Policy policy READ policy)
  314. public:
  315. QSizePolicy::Policy policy() const { return QSizePolicy::Ignored; }
  316. private:
  317. QtMetaEnumWrapper(QObject *parent) : QObject(parent) {}
  318. };
  319. class QtMetaEnumProvider
  320. {
  321. public:
  322. QtMetaEnumProvider();
  323. QStringList policyEnumNames() const { return m_policyEnumNames; }
  324. QStringList languageEnumNames() const { return m_languageEnumNames; }
  325. QStringList countryEnumNames(QLocale::Language language) const { return m_countryEnumNames.value(language); }
  326. QSizePolicy::Policy indexToSizePolicy(int index) const;
  327. int sizePolicyToIndex(QSizePolicy::Policy policy) const;
  328. void indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const;
  329. void localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const;
  330. private:
  331. void initLocale();
  332. QStringList m_policyEnumNames;
  333. QStringList m_languageEnumNames;
  334. QMap<QLocale::Language, QStringList> m_countryEnumNames;
  335. QMap<int, QLocale::Language> m_indexToLanguage;
  336. QMap<QLocale::Language, int> m_languageToIndex;
  337. QMap<int, QMap<int, QLocale::Country> > m_indexToCountry;
  338. QMap<QLocale::Language, QMap<QLocale::Country, int> > m_countryToIndex;
  339. QMetaEnum m_policyEnum;
  340. };
  341. static QList<QLocale::Country> sortCountries(const QList<QLocale::Country> &countries)
  342. {
  343. QMultiMap<QString, QLocale::Country> nameToCountry;
  344. for (QLocale::Country country : countries)
  345. nameToCountry.insert(QLocale::countryToString(country), country);
  346. return nameToCountry.values();
  347. }
  348. void QtMetaEnumProvider::initLocale()
  349. {
  350. QMultiMap<QString, QLocale::Language> nameToLanguage;
  351. for (int l = QLocale::C, last = QLocale::LastLanguage; l <= last; ++l) {
  352. const QLocale::Language language = static_cast<QLocale::Language>(l);
  353. QLocale locale(language);
  354. if (locale.language() == language)
  355. nameToLanguage.insert(QLocale::languageToString(language), language);
  356. }
  357. const QLocale system = QLocale::system();
  358. if (!nameToLanguage.contains(QLocale::languageToString(system.language())))
  359. nameToLanguage.insert(QLocale::languageToString(system.language()), system.language());
  360. const QList<QLocale::Language> languages = nameToLanguage.values();
  361. for (QLocale::Language language : languages) {
  362. QList<QLocale::Country> countries;
  363. countries = QLocale::countriesForLanguage(language);
  364. if (countries.isEmpty() && language == system.language())
  365. countries << system.country();
  366. if (!countries.isEmpty() && !m_languageToIndex.contains(language)) {
  367. countries = sortCountries(countries);
  368. int langIdx = m_languageEnumNames.count();
  369. m_indexToLanguage[langIdx] = language;
  370. m_languageToIndex[language] = langIdx;
  371. QStringList countryNames;
  372. int countryIdx = 0;
  373. for (QLocale::Country country : qAsConst(countries)) {
  374. countryNames << QLocale::countryToString(country);
  375. m_indexToCountry[langIdx][countryIdx] = country;
  376. m_countryToIndex[language][country] = countryIdx;
  377. ++countryIdx;
  378. }
  379. m_languageEnumNames << QLocale::languageToString(language);
  380. m_countryEnumNames[language] = countryNames;
  381. }
  382. }
  383. }
  384. QtMetaEnumProvider::QtMetaEnumProvider()
  385. {
  386. QMetaProperty p;
  387. p = QtMetaEnumWrapper::staticMetaObject.property(
  388. QtMetaEnumWrapper::staticMetaObject.propertyOffset() + 0);
  389. m_policyEnum = p.enumerator();
  390. const int keyCount = m_policyEnum.keyCount();
  391. for (int i = 0; i < keyCount; i++)
  392. m_policyEnumNames << QLatin1String(m_policyEnum.key(i));
  393. initLocale();
  394. }
  395. QSizePolicy::Policy QtMetaEnumProvider::indexToSizePolicy(int index) const
  396. {
  397. return static_cast<QSizePolicy::Policy>(m_policyEnum.value(index));
  398. }
  399. int QtMetaEnumProvider::sizePolicyToIndex(QSizePolicy::Policy policy) const
  400. {
  401. const int keyCount = m_policyEnum.keyCount();
  402. for (int i = 0; i < keyCount; i++)
  403. if (indexToSizePolicy(i) == policy)
  404. return i;
  405. return -1;
  406. }
  407. void QtMetaEnumProvider::indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const
  408. {
  409. QLocale::Language l = QLocale::C;
  410. QLocale::Country c = QLocale::AnyCountry;
  411. if (m_indexToLanguage.contains(languageIndex)) {
  412. l = m_indexToLanguage[languageIndex];
  413. if (m_indexToCountry.contains(languageIndex) && m_indexToCountry[languageIndex].contains(countryIndex))
  414. c = m_indexToCountry[languageIndex][countryIndex];
  415. }
  416. if (language)
  417. *language = l;
  418. if (country)
  419. *country = c;
  420. }
  421. void QtMetaEnumProvider::localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const
  422. {
  423. int l = -1;
  424. int c = -1;
  425. if (m_languageToIndex.contains(language)) {
  426. l = m_languageToIndex[language];
  427. if (m_countryToIndex.contains(language) && m_countryToIndex[language].contains(country))
  428. c = m_countryToIndex[language][country];
  429. }
  430. if (languageIndex)
  431. *languageIndex = l;
  432. if (countryIndex)
  433. *countryIndex = c;
  434. }
  435. Q_GLOBAL_STATIC(QtMetaEnumProvider, metaEnumProvider)
  436. // QtGroupPropertyManager
  437. /*!
  438. \class QtGroupPropertyManager
  439. \internal
  440. \inmodule QtDesigner
  441. \since 4.4
  442. \brief The QtGroupPropertyManager provides and manages group properties.
  443. This class is intended to provide a grouping element without any value.
  444. \sa QtAbstractPropertyManager
  445. */
  446. /*!
  447. Creates a manager with the given \a parent.
  448. */
  449. QtGroupPropertyManager::QtGroupPropertyManager(QObject *parent)
  450. : QtAbstractPropertyManager(parent)
  451. {
  452. }
  453. /*!
  454. Destroys this manager, and all the properties it has created.
  455. */
  456. QtGroupPropertyManager::~QtGroupPropertyManager()
  457. {
  458. }
  459. /*!
  460. \reimp
  461. */
  462. bool QtGroupPropertyManager::hasValue(const QtProperty *property) const
  463. {
  464. Q_UNUSED(property);
  465. return false;
  466. }
  467. /*!
  468. \reimp
  469. */
  470. void QtGroupPropertyManager::initializeProperty(QtProperty *property)
  471. {
  472. Q_UNUSED(property);
  473. }
  474. /*!
  475. \reimp
  476. */
  477. void QtGroupPropertyManager::uninitializeProperty(QtProperty *property)
  478. {
  479. Q_UNUSED(property);
  480. }
  481. // QtIntPropertyManager
  482. class QtIntPropertyManagerPrivate
  483. {
  484. QtIntPropertyManager *q_ptr;
  485. Q_DECLARE_PUBLIC(QtIntPropertyManager)
  486. public:
  487. struct Data
  488. {
  489. int val{0};
  490. int minVal{-INT_MAX};
  491. int maxVal{INT_MAX};
  492. int singleStep{1};
  493. int minimumValue() const { return minVal; }
  494. int maximumValue() const { return maxVal; }
  495. void setMinimumValue(int newMinVal) { setSimpleMinimumData(this, newMinVal); }
  496. void setMaximumValue(int newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
  497. };
  498. typedef QMap<const QtProperty *, Data> PropertyValueMap;
  499. PropertyValueMap m_values;
  500. };
  501. /*!
  502. \class QtIntPropertyManager
  503. \internal
  504. \inmodule QtDesigner
  505. \since 4.4
  506. \brief The QtIntPropertyManager provides and manages int properties.
  507. An int property has a current value, and a range specifying the
  508. valid values. The range is defined by a minimum and a maximum
  509. value.
  510. The property's value and range can be retrieved using the value(),
  511. minimum() and maximum() functions, and can be set using the
  512. setValue(), setMinimum() and setMaximum() slots. Alternatively,
  513. the range can be defined in one go using the setRange() slot.
  514. In addition, QtIntPropertyManager provides the valueChanged() signal which
  515. is emitted whenever a property created by this manager changes,
  516. and the rangeChanged() signal which is emitted whenever such a
  517. property changes its range of valid values.
  518. \sa QtAbstractPropertyManager, QtSpinBoxFactory, QtSliderFactory, QtScrollBarFactory
  519. */
  520. /*!
  521. \fn void QtIntPropertyManager::valueChanged(QtProperty *property, int value)
  522. This signal is emitted whenever a property created by this manager
  523. changes its value, passing a pointer to the \a property and the new
  524. \a value as parameters.
  525. \sa setValue()
  526. */
  527. /*!
  528. \fn void QtIntPropertyManager::rangeChanged(QtProperty *property, int minimum, int maximum)
  529. This signal is emitted whenever a property created by this manager
  530. changes its range of valid values, passing a pointer to the
  531. \a property and the new \a minimum and \a maximum values.
  532. \sa setRange()
  533. */
  534. /*!
  535. \fn void QtIntPropertyManager::singleStepChanged(QtProperty *property, int step)
  536. This signal is emitted whenever a property created by this manager
  537. changes its single step property, passing a pointer to the
  538. \a property and the new \a step value
  539. \sa setSingleStep()
  540. */
  541. /*!
  542. Creates a manager with the given \a parent.
  543. */
  544. QtIntPropertyManager::QtIntPropertyManager(QObject *parent)
  545. : QtAbstractPropertyManager(parent), d_ptr(new QtIntPropertyManagerPrivate)
  546. {
  547. d_ptr->q_ptr = this;
  548. }
  549. /*!
  550. Destroys this manager, and all the properties it has created.
  551. */
  552. QtIntPropertyManager::~QtIntPropertyManager()
  553. {
  554. clear();
  555. }
  556. /*!
  557. Returns the given \a property's value.
  558. If the given property is not managed by this manager, this
  559. function returns 0.
  560. \sa setValue()
  561. */
  562. int QtIntPropertyManager::value(const QtProperty *property) const
  563. {
  564. return getValue<int>(d_ptr->m_values, property, 0);
  565. }
  566. /*!
  567. Returns the given \a property's minimum value.
  568. \sa setMinimum(), maximum(), setRange()
  569. */
  570. int QtIntPropertyManager::minimum(const QtProperty *property) const
  571. {
  572. return getMinimum<int>(d_ptr->m_values, property, 0);
  573. }
  574. /*!
  575. Returns the given \a property's maximum value.
  576. \sa setMaximum(), minimum(), setRange()
  577. */
  578. int QtIntPropertyManager::maximum(const QtProperty *property) const
  579. {
  580. return getMaximum<int>(d_ptr->m_values, property, 0);
  581. }
  582. /*!
  583. Returns the given \a property's step value.
  584. The step is typically used to increment or decrement a property value while pressing an arrow key.
  585. \sa setSingleStep()
  586. */
  587. int QtIntPropertyManager::singleStep(const QtProperty *property) const
  588. {
  589. return getData<int>(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::singleStep, property, 0);
  590. }
  591. /*!
  592. \reimp
  593. */
  594. QString QtIntPropertyManager::valueText(const QtProperty *property) const
  595. {
  596. const QtIntPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  597. if (it == d_ptr->m_values.constEnd())
  598. return QString();
  599. return QString::number(it.value().val);
  600. }
  601. /*!
  602. \fn void QtIntPropertyManager::setValue(QtProperty *property, int value)
  603. Sets the value of the given \a property to \a value.
  604. If the specified \a value is not valid according to the given \a
  605. property's range, the \a value is adjusted to the nearest valid
  606. value within the range.
  607. \sa value(), setRange(), valueChanged()
  608. */
  609. void QtIntPropertyManager::setValue(QtProperty *property, int val)
  610. {
  611. void (QtIntPropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, int) = 0;
  612. setValueInRange<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr.data(),
  613. &QtIntPropertyManager::propertyChanged,
  614. &QtIntPropertyManager::valueChanged,
  615. property, val, setSubPropertyValue);
  616. }
  617. /*!
  618. Sets the minimum value for the given \a property to \a minVal.
  619. When setting the minimum value, the maximum and current values are
  620. adjusted if necessary (ensuring that the range remains valid and
  621. that the current value is within the range).
  622. \sa minimum(), setRange(), rangeChanged()
  623. */
  624. void QtIntPropertyManager::setMinimum(QtProperty *property, int minVal)
  625. {
  626. setMinimumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr.data(),
  627. &QtIntPropertyManager::propertyChanged,
  628. &QtIntPropertyManager::valueChanged,
  629. &QtIntPropertyManager::rangeChanged,
  630. property, minVal);
  631. }
  632. /*!
  633. Sets the maximum value for the given \a property to \a maxVal.
  634. When setting maximum value, the minimum and current values are
  635. adjusted if necessary (ensuring that the range remains valid and
  636. that the current value is within the range).
  637. \sa maximum(), setRange(), rangeChanged()
  638. */
  639. void QtIntPropertyManager::setMaximum(QtProperty *property, int maxVal)
  640. {
  641. setMaximumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr.data(),
  642. &QtIntPropertyManager::propertyChanged,
  643. &QtIntPropertyManager::valueChanged,
  644. &QtIntPropertyManager::rangeChanged,
  645. property, maxVal);
  646. }
  647. /*!
  648. \fn void QtIntPropertyManager::setRange(QtProperty *property, int minimum, int maximum)
  649. Sets the range of valid values.
  650. This is a convenience function defining the range of valid values
  651. in one go; setting the \a minimum and \a maximum values for the
  652. given \a property with a single function call.
  653. When setting a new range, the current value is adjusted if
  654. necessary (ensuring that the value remains within range).
  655. \sa setMinimum(), setMaximum(), rangeChanged()
  656. */
  657. void QtIntPropertyManager::setRange(QtProperty *property, int minVal, int maxVal)
  658. {
  659. void (QtIntPropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, int, int, int) = 0;
  660. setBorderValues<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr.data(),
  661. &QtIntPropertyManager::propertyChanged,
  662. &QtIntPropertyManager::valueChanged,
  663. &QtIntPropertyManager::rangeChanged,
  664. property, minVal, maxVal, setSubPropertyRange);
  665. }
  666. /*!
  667. Sets the step value for the given \a property to \a step.
  668. The step is typically used to increment or decrement a property value while pressing an arrow key.
  669. \sa singleStep()
  670. */
  671. void QtIntPropertyManager::setSingleStep(QtProperty *property, int step)
  672. {
  673. const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  674. if (it == d_ptr->m_values.end())
  675. return;
  676. QtIntPropertyManagerPrivate::Data data = it.value();
  677. if (step < 0)
  678. step = 0;
  679. if (data.singleStep == step)
  680. return;
  681. data.singleStep = step;
  682. it.value() = data;
  683. emit singleStepChanged(property, data.singleStep);
  684. }
  685. /*!
  686. \reimp
  687. */
  688. void QtIntPropertyManager::initializeProperty(QtProperty *property)
  689. {
  690. d_ptr->m_values[property] = QtIntPropertyManagerPrivate::Data();
  691. }
  692. /*!
  693. \reimp
  694. */
  695. void QtIntPropertyManager::uninitializeProperty(QtProperty *property)
  696. {
  697. d_ptr->m_values.remove(property);
  698. }
  699. // QtDoublePropertyManager
  700. class QtDoublePropertyManagerPrivate
  701. {
  702. QtDoublePropertyManager *q_ptr;
  703. Q_DECLARE_PUBLIC(QtDoublePropertyManager)
  704. public:
  705. struct Data
  706. {
  707. double val{0};
  708. double minVal{-DBL_MAX};
  709. double maxVal{DBL_MAX};
  710. double singleStep{1};
  711. int decimals{2};
  712. double minimumValue() const { return minVal; }
  713. double maximumValue() const { return maxVal; }
  714. void setMinimumValue(double newMinVal) { setSimpleMinimumData(this, newMinVal); }
  715. void setMaximumValue(double newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
  716. };
  717. typedef QMap<const QtProperty *, Data> PropertyValueMap;
  718. PropertyValueMap m_values;
  719. };
  720. /*!
  721. \class QtDoublePropertyManager
  722. \internal
  723. \inmodule QtDesigner
  724. \since 4.4
  725. \brief The QtDoublePropertyManager provides and manages double properties.
  726. A double property has a current value, and a range specifying the
  727. valid values. The range is defined by a minimum and a maximum
  728. value.
  729. The property's value and range can be retrieved using the value(),
  730. minimum() and maximum() functions, and can be set using the
  731. setValue(), setMinimum() and setMaximum() slots.
  732. Alternatively, the range can be defined in one go using the
  733. setRange() slot.
  734. In addition, QtDoublePropertyManager provides the valueChanged() signal
  735. which is emitted whenever a property created by this manager
  736. changes, and the rangeChanged() signal which is emitted whenever
  737. such a property changes its range of valid values.
  738. \sa QtAbstractPropertyManager, QtDoubleSpinBoxFactory
  739. */
  740. /*!
  741. \fn void QtDoublePropertyManager::valueChanged(QtProperty *property, double value)
  742. This signal is emitted whenever a property created by this manager
  743. changes its value, passing a pointer to the \a property and the new
  744. \a value as parameters.
  745. \sa setValue()
  746. */
  747. /*!
  748. \fn void QtDoublePropertyManager::rangeChanged(QtProperty *property, double minimum, double maximum)
  749. This signal is emitted whenever a property created by this manager
  750. changes its range of valid values, passing a pointer to the
  751. \a property and the new \a minimum and \a maximum values
  752. \sa setRange()
  753. */
  754. /*!
  755. \fn void QtDoublePropertyManager::decimalsChanged(QtProperty *property, int prec)
  756. This signal is emitted whenever a property created by this manager
  757. changes its precision of value, passing a pointer to the
  758. \a property and the new \a prec value
  759. \sa setDecimals()
  760. */
  761. /*!
  762. \fn void QtDoublePropertyManager::singleStepChanged(QtProperty *property, double step)
  763. This signal is emitted whenever a property created by this manager
  764. changes its single step property, passing a pointer to the
  765. \a property and the new \a step value
  766. \sa setSingleStep()
  767. */
  768. /*!
  769. Creates a manager with the given \a parent.
  770. */
  771. QtDoublePropertyManager::QtDoublePropertyManager(QObject *parent)
  772. : QtAbstractPropertyManager(parent), d_ptr(new QtDoublePropertyManagerPrivate)
  773. {
  774. d_ptr->q_ptr = this;
  775. }
  776. /*!
  777. Destroys this manager, and all the properties it has created.
  778. */
  779. QtDoublePropertyManager::~QtDoublePropertyManager()
  780. {
  781. clear();
  782. }
  783. /*!
  784. Returns the given \a property's value.
  785. If the given property is not managed by this manager, this
  786. function returns 0.
  787. \sa setValue()
  788. */
  789. double QtDoublePropertyManager::value(const QtProperty *property) const
  790. {
  791. return getValue<double>(d_ptr->m_values, property, 0.0);
  792. }
  793. /*!
  794. Returns the given \a property's minimum value.
  795. \sa maximum(), setRange()
  796. */
  797. double QtDoublePropertyManager::minimum(const QtProperty *property) const
  798. {
  799. return getMinimum<double>(d_ptr->m_values, property, 0.0);
  800. }
  801. /*!
  802. Returns the given \a property's maximum value.
  803. \sa minimum(), setRange()
  804. */
  805. double QtDoublePropertyManager::maximum(const QtProperty *property) const
  806. {
  807. return getMaximum<double>(d_ptr->m_values, property, 0.0);
  808. }
  809. /*!
  810. Returns the given \a property's step value.
  811. The step is typically used to increment or decrement a property value while pressing an arrow key.
  812. \sa setSingleStep()
  813. */
  814. double QtDoublePropertyManager::singleStep(const QtProperty *property) const
  815. {
  816. return getData<double>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::singleStep, property, 0);
  817. }
  818. /*!
  819. Returns the given \a property's precision, in decimals.
  820. \sa setDecimals()
  821. */
  822. int QtDoublePropertyManager::decimals(const QtProperty *property) const
  823. {
  824. return getData<int>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::decimals, property, 0);
  825. }
  826. /*!
  827. \reimp
  828. */
  829. QString QtDoublePropertyManager::valueText(const QtProperty *property) const
  830. {
  831. const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  832. if (it == d_ptr->m_values.constEnd())
  833. return QString();
  834. return QString::number(it.value().val, 'f', it.value().decimals);
  835. }
  836. /*!
  837. \fn void QtDoublePropertyManager::setValue(QtProperty *property, double value)
  838. Sets the value of the given \a property to \a value.
  839. If the specified \a value is not valid according to the given
  840. \a property's range, the \a value is adjusted to the nearest valid value
  841. within the range.
  842. \sa value(), setRange(), valueChanged()
  843. */
  844. void QtDoublePropertyManager::setValue(QtProperty *property, double val)
  845. {
  846. void (QtDoublePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, double) = 0;
  847. setValueInRange<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr.data(),
  848. &QtDoublePropertyManager::propertyChanged,
  849. &QtDoublePropertyManager::valueChanged,
  850. property, val, setSubPropertyValue);
  851. }
  852. /*!
  853. Sets the step value for the given \a property to \a step.
  854. The step is typically used to increment or decrement a property value while pressing an arrow key.
  855. \sa singleStep()
  856. */
  857. void QtDoublePropertyManager::setSingleStep(QtProperty *property, double step)
  858. {
  859. const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  860. if (it == d_ptr->m_values.end())
  861. return;
  862. QtDoublePropertyManagerPrivate::Data data = it.value();
  863. if (step < 0)
  864. step = 0;
  865. if (data.singleStep == step)
  866. return;
  867. data.singleStep = step;
  868. it.value() = data;
  869. emit singleStepChanged(property, data.singleStep);
  870. }
  871. /*!
  872. \fn void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
  873. Sets the precision of the given \a property to \a prec.
  874. The valid decimal range is 0-13. The default is 2.
  875. \sa decimals()
  876. */
  877. void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
  878. {
  879. const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  880. if (it == d_ptr->m_values.end())
  881. return;
  882. QtDoublePropertyManagerPrivate::Data data = it.value();
  883. if (prec > 13)
  884. prec = 13;
  885. else if (prec < 0)
  886. prec = 0;
  887. if (data.decimals == prec)
  888. return;
  889. data.decimals = prec;
  890. it.value() = data;
  891. emit decimalsChanged(property, data.decimals);
  892. }
  893. /*!
  894. Sets the minimum value for the given \a property to \a minVal.
  895. When setting the minimum value, the maximum and current values are
  896. adjusted if necessary (ensuring that the range remains valid and
  897. that the current value is within in the range).
  898. \sa minimum(), setRange(), rangeChanged()
  899. */
  900. void QtDoublePropertyManager::setMinimum(QtProperty *property, double minVal)
  901. {
  902. setMinimumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr.data(),
  903. &QtDoublePropertyManager::propertyChanged,
  904. &QtDoublePropertyManager::valueChanged,
  905. &QtDoublePropertyManager::rangeChanged,
  906. property, minVal);
  907. }
  908. /*!
  909. Sets the maximum value for the given \a property to \a maxVal.
  910. When setting the maximum value, the minimum and current values are
  911. adjusted if necessary (ensuring that the range remains valid and
  912. that the current value is within in the range).
  913. \sa maximum(), setRange(), rangeChanged()
  914. */
  915. void QtDoublePropertyManager::setMaximum(QtProperty *property, double maxVal)
  916. {
  917. setMaximumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr.data(),
  918. &QtDoublePropertyManager::propertyChanged,
  919. &QtDoublePropertyManager::valueChanged,
  920. &QtDoublePropertyManager::rangeChanged,
  921. property, maxVal);
  922. }
  923. /*!
  924. \fn void QtDoublePropertyManager::setRange(QtProperty *property, double minimum, double maximum)
  925. Sets the range of valid values.
  926. This is a convenience function defining the range of valid values
  927. in one go; setting the \a minimum and \a maximum values for the
  928. given \a property with a single function call.
  929. When setting a new range, the current value is adjusted if
  930. necessary (ensuring that the value remains within range).
  931. \sa setMinimum(), setMaximum(), rangeChanged()
  932. */
  933. void QtDoublePropertyManager::setRange(QtProperty *property, double minVal, double maxVal)
  934. {
  935. void (QtDoublePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, double, double, double) = 0;
  936. setBorderValues<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr.data(),
  937. &QtDoublePropertyManager::propertyChanged,
  938. &QtDoublePropertyManager::valueChanged,
  939. &QtDoublePropertyManager::rangeChanged,
  940. property, minVal, maxVal, setSubPropertyRange);
  941. }
  942. /*!
  943. \reimp
  944. */
  945. void QtDoublePropertyManager::initializeProperty(QtProperty *property)
  946. {
  947. d_ptr->m_values[property] = QtDoublePropertyManagerPrivate::Data();
  948. }
  949. /*!
  950. \reimp
  951. */
  952. void QtDoublePropertyManager::uninitializeProperty(QtProperty *property)
  953. {
  954. d_ptr->m_values.remove(property);
  955. }
  956. // QtStringPropertyManager
  957. class QtStringPropertyManagerPrivate
  958. {
  959. QtStringPropertyManager *q_ptr;
  960. Q_DECLARE_PUBLIC(QtStringPropertyManager)
  961. public:
  962. struct Data
  963. {
  964. Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard)
  965. {
  966. }
  967. QString val;
  968. QRegExp regExp;
  969. };
  970. typedef QMap<const QtProperty *, Data> PropertyValueMap;
  971. QMap<const QtProperty *, Data> m_values;
  972. };
  973. /*!
  974. \class QtStringPropertyManager
  975. \internal
  976. \inmodule QtDesigner
  977. \since 4.4
  978. \brief The QtStringPropertyManager provides and manages QString properties.
  979. A string property's value can be retrieved using the value()
  980. function, and set using the setValue() slot.
  981. The current value can be checked against a regular expression. To
  982. set the regular expression use the setRegExp() slot, use the
  983. regExp() function to retrieve the currently set expression.
  984. In addition, QtStringPropertyManager provides the valueChanged() signal
  985. which is emitted whenever a property created by this manager
  986. changes, and the regExpChanged() signal which is emitted whenever
  987. such a property changes its currently set regular expression.
  988. \sa QtAbstractPropertyManager, QtLineEditFactory
  989. */
  990. /*!
  991. \fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value)
  992. This signal is emitted whenever a property created by this manager
  993. changes its value, passing a pointer to the \a property and the
  994. new \a value as parameters.
  995. \sa setValue()
  996. */
  997. /*!
  998. \fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegExp &regExp)
  999. This signal is emitted whenever a property created by this manager
  1000. changes its currenlty set regular expression, passing a pointer to
  1001. the \a property and the new \a regExp as parameters.
  1002. \sa setRegExp()
  1003. */
  1004. /*!
  1005. Creates a manager with the given \a parent.
  1006. */
  1007. QtStringPropertyManager::QtStringPropertyManager(QObject *parent)
  1008. : QtAbstractPropertyManager(parent), d_ptr(new QtStringPropertyManagerPrivate)
  1009. {
  1010. d_ptr->q_ptr = this;
  1011. }
  1012. /*!
  1013. Destroys this manager, and all the properties it has created.
  1014. */
  1015. QtStringPropertyManager::~QtStringPropertyManager()
  1016. {
  1017. clear();
  1018. }
  1019. /*!
  1020. Returns the given \a property's value.
  1021. If the given property is not managed by this manager, this
  1022. function returns an empty string.
  1023. \sa setValue()
  1024. */
  1025. QString QtStringPropertyManager::value(const QtProperty *property) const
  1026. {
  1027. return getValue<QString>(d_ptr->m_values, property);
  1028. }
  1029. /*!
  1030. Returns the given \a property's currently set regular expression.
  1031. If the given \a property is not managed by this manager, this
  1032. function returns an empty expression.
  1033. \sa setRegExp()
  1034. */
  1035. QRegExp QtStringPropertyManager::regExp(const QtProperty *property) const
  1036. {
  1037. return getData<QRegExp>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegExp());
  1038. }
  1039. /*!
  1040. \reimp
  1041. */
  1042. QString QtStringPropertyManager::valueText(const QtProperty *property) const
  1043. {
  1044. const QtStringPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  1045. if (it == d_ptr->m_values.constEnd())
  1046. return QString();
  1047. return it.value().val;
  1048. }
  1049. /*!
  1050. \fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value)
  1051. Sets the value of the given \a property to \a value.
  1052. If the specified \a value doesn't match the given \a property's
  1053. regular expression, this function does nothing.
  1054. \sa value(), setRegExp(), valueChanged()
  1055. */
  1056. void QtStringPropertyManager::setValue(QtProperty *property, const QString &val)
  1057. {
  1058. const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  1059. if (it == d_ptr->m_values.end())
  1060. return;
  1061. QtStringPropertyManagerPrivate::Data data = it.value();
  1062. if (data.val == val)
  1063. return;
  1064. if (data.regExp.isValid() && !data.regExp.exactMatch(val))
  1065. return;
  1066. data.val = val;
  1067. it.value() = data;
  1068. emit propertyChanged(property);
  1069. emit valueChanged(property, data.val);
  1070. }
  1071. /*!
  1072. Sets the regular expression of the given \a property to \a regExp.
  1073. \sa regExp(), setValue(), regExpChanged()
  1074. */
  1075. void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegExp &regExp)
  1076. {
  1077. const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  1078. if (it == d_ptr->m_values.end())
  1079. return;
  1080. QtStringPropertyManagerPrivate::Data data = it.value() ;
  1081. if (data.regExp == regExp)
  1082. return;
  1083. data.regExp = regExp;
  1084. it.value() = data;
  1085. emit regExpChanged(property, data.regExp);
  1086. }
  1087. /*!
  1088. \reimp
  1089. */
  1090. void QtStringPropertyManager::initializeProperty(QtProperty *property)
  1091. {
  1092. d_ptr->m_values[property] = QtStringPropertyManagerPrivate::Data();
  1093. }
  1094. /*!
  1095. \reimp
  1096. */
  1097. void QtStringPropertyManager::uninitializeProperty(QtProperty *property)
  1098. {
  1099. d_ptr->m_values.remove(property);
  1100. }
  1101. // QtBoolPropertyManager
  1102. // Return an icon containing a check box indicator
  1103. static QIcon drawCheckBox(bool value)
  1104. {
  1105. QStyleOptionButton opt;
  1106. opt.state |= value ? QStyle::State_On : QStyle::State_Off;
  1107. opt.state |= QStyle::State_Enabled;
  1108. const QStyle *style = QApplication::style();
  1109. // Figure out size of an indicator and make sure it is not scaled down in a list view item
  1110. // by making the pixmap as big as a list view icon and centering the indicator in it.
  1111. // (if it is smaller, it can't be helped)
  1112. const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt);
  1113. const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt);
  1114. const int listViewIconSize = indicatorWidth;
  1115. const int pixmapWidth = indicatorWidth;
  1116. const int pixmapHeight = qMax(indicatorHeight, listViewIconSize);
  1117. opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight);
  1118. QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight);
  1119. pixmap.fill(Qt::transparent);
  1120. {
  1121. // Center?
  1122. const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0;
  1123. const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0;
  1124. QPainter painter(&pixmap);
  1125. painter.translate(xoff, yoff);
  1126. style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
  1127. }
  1128. return QIcon(pixmap);
  1129. }
  1130. class QtBoolPropertyManagerPrivate
  1131. {
  1132. QtBoolPropertyManager *q_ptr;
  1133. Q_DECLARE_PUBLIC(QtBoolPropertyManager)
  1134. public:
  1135. QtBoolPropertyManagerPrivate();
  1136. QMap<const QtProperty *, bool> m_values;
  1137. const QIcon m_checkedIcon;
  1138. const QIcon m_uncheckedIcon;
  1139. };
  1140. QtBoolPropertyManagerPrivate::QtBoolPropertyManagerPrivate() :
  1141. m_checkedIcon(drawCheckBox(true)),
  1142. m_uncheckedIcon(drawCheckBox(false))
  1143. {
  1144. }
  1145. /*!
  1146. \class QtBoolPropertyManager
  1147. \internal
  1148. \inmodule QtDesigner
  1149. \since 4.4
  1150. \brief The QtBoolPropertyManager class provides and manages boolean properties.
  1151. The property's value can be retrieved using the value() function,
  1152. and set using the setValue() slot.
  1153. In addition, QtBoolPropertyManager provides the valueChanged() signal
  1154. which is emitted whenever a property created by this manager
  1155. changes.
  1156. \sa QtAbstractPropertyManager, QtCheckBoxFactory
  1157. */
  1158. /*!
  1159. \fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value)
  1160. This signal is emitted whenever a property created by this manager
  1161. changes its value, passing a pointer to the \a property and the
  1162. new \a value as parameters.
  1163. */
  1164. /*!
  1165. Creates a manager with the given \a parent.
  1166. */
  1167. QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent)
  1168. : QtAbstractPropertyManager(parent), d_ptr(new QtBoolPropertyManagerPrivate)
  1169. {
  1170. d_ptr->q_ptr = this;
  1171. }
  1172. /*!
  1173. Destroys this manager, and all the properties it has created.
  1174. */
  1175. QtBoolPropertyManager::~QtBoolPropertyManager()
  1176. {
  1177. clear();
  1178. }
  1179. /*!
  1180. Returns the given \a property's value.
  1181. If the given \a property is not managed by \e this manager, this
  1182. function returns false.
  1183. \sa setValue()
  1184. */
  1185. bool QtBoolPropertyManager::value(const QtProperty *property) const
  1186. {
  1187. return d_ptr->m_values.value(property, false);
  1188. }
  1189. /*!
  1190. \reimp
  1191. */
  1192. QString QtBoolPropertyManager::valueText(const QtProperty *property) const
  1193. {
  1194. const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
  1195. if (it == d_ptr->m_values.constEnd())
  1196. return QString();
  1197. static const QString trueText = tr("True");
  1198. static const QString falseText = tr("False");
  1199. return it.value() ? trueText : falseText;
  1200. }
  1201. /*!
  1202. \reimp
  1203. */
  1204. QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const
  1205. {
  1206. const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
  1207. if (it == d_ptr->m_values.constEnd())
  1208. return QIcon();
  1209. return it.value() ? d_ptr->m_checkedIcon : d_ptr->m_uncheckedIcon;
  1210. }
  1211. /*!
  1212. \fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value)
  1213. Sets the value of the given \a property to \a value.
  1214. \sa value()
  1215. */
  1216. void QtBoolPropertyManager::setValue(QtProperty *property, bool val)
  1217. {
  1218. setSimpleValue<bool, bool, QtBoolPropertyManager>(d_ptr->m_values, this,
  1219. &QtBoolPropertyManager::propertyChanged,
  1220. &QtBoolPropertyManager::valueChanged,
  1221. property, val);
  1222. }
  1223. /*!
  1224. \reimp
  1225. */
  1226. void QtBoolPropertyManager::initializeProperty(QtProperty *property)
  1227. {
  1228. d_ptr->m_values[property] = false;
  1229. }
  1230. /*!
  1231. \reimp
  1232. */
  1233. void QtBoolPropertyManager::uninitializeProperty(QtProperty *property)
  1234. {
  1235. d_ptr->m_values.remove(property);
  1236. }
  1237. // QtDatePropertyManager
  1238. class QtDatePropertyManagerPrivate
  1239. {
  1240. QtDatePropertyManager *q_ptr;
  1241. Q_DECLARE_PUBLIC(QtDatePropertyManager)
  1242. public:
  1243. explicit QtDatePropertyManagerPrivate(QtDatePropertyManager *q);
  1244. struct Data
  1245. {
  1246. QDate val{QDate::currentDate()};
  1247. QDate minVal{QDate(1752, 9, 14)};
  1248. QDate maxVal{QDate(9999, 12, 31)};
  1249. QDate minimumValue() const { return minVal; }
  1250. QDate maximumValue() const { return maxVal; }
  1251. void setMinimumValue(const QDate &newMinVal) { setSimpleMinimumData(this, newMinVal); }
  1252. void setMaximumValue(const QDate &newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
  1253. };
  1254. QString m_format;
  1255. typedef QMap<const QtProperty *, Data> PropertyValueMap;
  1256. QMap<const QtProperty *, Data> m_values;
  1257. };
  1258. QtDatePropertyManagerPrivate::QtDatePropertyManagerPrivate(QtDatePropertyManager *q) :
  1259. q_ptr(q),
  1260. m_format(QtPropertyBrowserUtils::dateFormat())
  1261. {
  1262. }
  1263. /*!
  1264. \class QtDatePropertyManager
  1265. \internal
  1266. \inmodule QtDesigner
  1267. \since 4.4
  1268. \brief The QtDatePropertyManager provides and manages QDate properties.
  1269. A date property has a current value, and a range specifying the
  1270. valid dates. The range is defined by a minimum and a maximum
  1271. value.
  1272. The property's values can be retrieved using the minimum(),
  1273. maximum() and value() functions, and can be set using the
  1274. setMinimum(), setMaximum() and setValue() slots. Alternatively,
  1275. the range can be defined in one go using the setRange() slot.
  1276. In addition, QtDatePropertyManager provides the valueChanged() signal
  1277. which is emitted whenever a property created by this manager
  1278. changes, and the rangeChanged() signal which is emitted whenever
  1279. such a property changes its range of valid dates.
  1280. \sa QtAbstractPropertyManager, QtDateEditFactory, QtDateTimePropertyManager
  1281. */
  1282. /*!
  1283. \fn void QtDatePropertyManager::valueChanged(QtProperty *property, const QDate &value)
  1284. This signal is emitted whenever a property created by this manager
  1285. changes its value, passing a pointer to the \a property and the new
  1286. \a value as parameters.
  1287. \sa setValue()
  1288. */
  1289. /*!
  1290. \fn void QtDatePropertyManager::rangeChanged(QtProperty *property, const QDate &minimum, const QDate &maximum)
  1291. This signal is emitted whenever a property created by this manager
  1292. changes its range of valid dates, passing a pointer to the \a
  1293. property and the new \a minimum and \a maximum dates.
  1294. \sa setRange()
  1295. */
  1296. /*!
  1297. Creates a manager with the given \a parent.
  1298. */
  1299. QtDatePropertyManager::QtDatePropertyManager(QObject *parent)
  1300. : QtAbstractPropertyManager(parent), d_ptr(new QtDatePropertyManagerPrivate(this))
  1301. {
  1302. }
  1303. /*!
  1304. Destroys this manager, and all the properties it has created.
  1305. */
  1306. QtDatePropertyManager::~QtDatePropertyManager()
  1307. {
  1308. clear();
  1309. }
  1310. /*!
  1311. Returns the given \a property's value.
  1312. If the given \a property is not managed by \e this manager, this
  1313. function returns an invalid date.
  1314. \sa setValue()
  1315. */
  1316. QDate QtDatePropertyManager::value(const QtProperty *property) const
  1317. {
  1318. return getValue<QDate>(d_ptr->m_values, property);
  1319. }
  1320. /*!
  1321. Returns the given \a property's minimum date.
  1322. \sa maximum(), setRange()
  1323. */
  1324. QDate QtDatePropertyManager::minimum(const QtProperty *property) const
  1325. {
  1326. return getMinimum<QDate>(d_ptr->m_values, property);
  1327. }
  1328. /*!
  1329. Returns the given \a property's maximum date.
  1330. \sa minimum(), setRange()
  1331. */
  1332. QDate QtDatePropertyManager::maximum(const QtProperty *property) const
  1333. {
  1334. return getMaximum<QDate>(d_ptr->m_values, property);
  1335. }
  1336. /*!
  1337. \reimp
  1338. */
  1339. QString QtDatePropertyManager::valueText(const QtProperty *property) const
  1340. {
  1341. const QtDatePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  1342. if (it == d_ptr->m_values.constEnd())
  1343. return QString();
  1344. return it.value().val.toString(d_ptr->m_format);
  1345. }
  1346. /*!
  1347. \fn void QtDatePropertyManager::setValue(QtProperty *property, const QDate &value)
  1348. Sets the value of the given \a property to \a value.
  1349. If the specified \a value is not a valid date according to the
  1350. given \a property's range, the value is adjusted to the nearest
  1351. valid value within the range.
  1352. \sa value(), setRange(), valueChanged()
  1353. */
  1354. void QtDatePropertyManager::setValue(QtProperty *property, const QDate &val)
  1355. {
  1356. void (QtDatePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, const QDate &) = 0;
  1357. setValueInRange<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, const QDate>(this, d_ptr.data(),
  1358. &QtDatePropertyManager::propertyChanged,
  1359. &QtDatePropertyManager::valueChanged,
  1360. property, val, setSubPropertyValue);
  1361. }
  1362. /*!
  1363. Sets the minimum value for the given \a property to \a minVal.
  1364. When setting the minimum value, the maximum and current values are
  1365. adjusted if necessary (ensuring that the range remains valid and
  1366. that the current value is within in the range).
  1367. \sa minimum(), setRange()
  1368. */
  1369. void QtDatePropertyManager::setMinimum(QtProperty *property, const QDate &minVal)
  1370. {
  1371. setMinimumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr.data(),
  1372. &QtDatePropertyManager::propertyChanged,
  1373. &QtDatePropertyManager::valueChanged,
  1374. &QtDatePropertyManager::rangeChanged,
  1375. property, minVal);
  1376. }
  1377. /*!
  1378. Sets the maximum value for the given \a property to \a maxVal.
  1379. When setting the maximum value, the minimum and current
  1380. values are adjusted if necessary (ensuring that the range remains
  1381. valid and that the current value is within in the range).
  1382. \sa maximum(), setRange()
  1383. */
  1384. void QtDatePropertyManager::setMaximum(QtProperty *property, const QDate &maxVal)
  1385. {
  1386. setMaximumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr.data(),
  1387. &QtDatePropertyManager::propertyChanged,
  1388. &QtDatePropertyManager::valueChanged,
  1389. &QtDatePropertyManager::rangeChanged,
  1390. property, maxVal);
  1391. }
  1392. /*!
  1393. \fn void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minimum, const QDate &maximum)
  1394. Sets the range of valid dates.
  1395. This is a convenience function defining the range of valid dates
  1396. in one go; setting the \a minimum and \a maximum values for the
  1397. given \a property with a single function call.
  1398. When setting a new date range, the current value is adjusted if
  1399. necessary (ensuring that the value remains in date range).
  1400. \sa setMinimum(), setMaximum(), rangeChanged()
  1401. */
  1402. void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minVal, const QDate &maxVal)
  1403. {
  1404. void (QtDatePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, const QDate &,
  1405. const QDate &, const QDate &) = 0;
  1406. setBorderValues<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate>(this, d_ptr.data(),
  1407. &QtDatePropertyManager::propertyChanged,
  1408. &QtDatePropertyManager::valueChanged,
  1409. &QtDatePropertyManager::rangeChanged,
  1410. property, minVal, maxVal, setSubPropertyRange);
  1411. }
  1412. /*!
  1413. \reimp
  1414. */
  1415. void QtDatePropertyManager::initializeProperty(QtProperty *property)
  1416. {
  1417. d_ptr->m_values[property] = QtDatePropertyManagerPrivate::Data();
  1418. }
  1419. /*!
  1420. \reimp
  1421. */
  1422. void QtDatePropertyManager::uninitializeProperty(QtProperty *property)
  1423. {
  1424. d_ptr->m_values.remove(property);
  1425. }
  1426. // QtTimePropertyManager
  1427. class QtTimePropertyManagerPrivate
  1428. {
  1429. QtTimePropertyManager *q_ptr;
  1430. Q_DECLARE_PUBLIC(QtTimePropertyManager)
  1431. public:
  1432. explicit QtTimePropertyManagerPrivate(QtTimePropertyManager *q);
  1433. const QString m_format;
  1434. typedef QMap<const QtProperty *, QTime> PropertyValueMap;
  1435. PropertyValueMap m_values;
  1436. };
  1437. QtTimePropertyManagerPrivate::QtTimePropertyManagerPrivate(QtTimePropertyManager *q) :
  1438. q_ptr(q),
  1439. m_format(QtPropertyBrowserUtils::timeFormat())
  1440. {
  1441. }
  1442. /*!
  1443. \class QtTimePropertyManager
  1444. \internal
  1445. \inmodule QtDesigner
  1446. \since 4.4
  1447. \brief The QtTimePropertyManager provides and manages QTime properties.
  1448. A time property's value can be retrieved using the value()
  1449. function, and set using the setValue() slot.
  1450. In addition, QtTimePropertyManager provides the valueChanged() signal
  1451. which is emitted whenever a property created by this manager
  1452. changes.
  1453. \sa QtAbstractPropertyManager, QtTimeEditFactory
  1454. */
  1455. /*!
  1456. \fn void QtTimePropertyManager::valueChanged(QtProperty *property, const QTime &value)
  1457. This signal is emitted whenever a property created by this manager
  1458. changes its value, passing a pointer to the \a property and the
  1459. new \a value as parameters.
  1460. \sa setValue()
  1461. */
  1462. /*!
  1463. Creates a manager with the given \a parent.
  1464. */
  1465. QtTimePropertyManager::QtTimePropertyManager(QObject *parent)
  1466. : QtAbstractPropertyManager(parent), d_ptr(new QtTimePropertyManagerPrivate(this))
  1467. {
  1468. }
  1469. /*!
  1470. Destroys this manager, and all the properties it has created.
  1471. */
  1472. QtTimePropertyManager::~QtTimePropertyManager()
  1473. {
  1474. clear();
  1475. }
  1476. /*!
  1477. Returns the given \a property's value.
  1478. If the given property is not managed by this manager, this
  1479. function returns an invalid time object.
  1480. \sa setValue()
  1481. */
  1482. QTime QtTimePropertyManager::value(const QtProperty *property) const
  1483. {
  1484. return d_ptr->m_values.value(property, QTime());
  1485. }
  1486. /*!
  1487. \reimp
  1488. */
  1489. QString QtTimePropertyManager::valueText(const QtProperty *property) const
  1490. {
  1491. const QtTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  1492. if (it == d_ptr->m_values.constEnd())
  1493. return QString();
  1494. return it.value().toString(d_ptr->m_format);
  1495. }
  1496. /*!
  1497. \fn void QtTimePropertyManager::setValue(QtProperty *property, const QTime &value)
  1498. Sets the value of the given \a property to \a value.
  1499. \sa value(), valueChanged()
  1500. */
  1501. void QtTimePropertyManager::setValue(QtProperty *property, const QTime &val)
  1502. {
  1503. setSimpleValue<const QTime &, QTime, QtTimePropertyManager>(d_ptr->m_values, this,
  1504. &QtTimePropertyManager::propertyChanged,
  1505. &QtTimePropertyManager::valueChanged,
  1506. property, val);
  1507. }
  1508. /*!
  1509. \reimp
  1510. */
  1511. void QtTimePropertyManager::initializeProperty(QtProperty *property)
  1512. {
  1513. d_ptr->m_values[property] = QTime::currentTime();
  1514. }
  1515. /*!
  1516. \reimp
  1517. */
  1518. void QtTimePropertyManager::uninitializeProperty(QtProperty *property)
  1519. {
  1520. d_ptr->m_values.remove(property);
  1521. }
  1522. // QtDateTimePropertyManager
  1523. class QtDateTimePropertyManagerPrivate
  1524. {
  1525. QtDateTimePropertyManager *q_ptr;
  1526. Q_DECLARE_PUBLIC(QtDateTimePropertyManager)
  1527. public:
  1528. explicit QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q);
  1529. const QString m_format;
  1530. typedef QMap<const QtProperty *, QDateTime> PropertyValueMap;
  1531. PropertyValueMap m_values;
  1532. };
  1533. QtDateTimePropertyManagerPrivate::QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q) :
  1534. q_ptr(q),
  1535. m_format(QtPropertyBrowserUtils::dateTimeFormat())
  1536. {
  1537. }
  1538. /*! \class QtDateTimePropertyManager
  1539. \internal
  1540. \inmodule QtDesigner
  1541. \since 4.4
  1542. \brief The QtDateTimePropertyManager provides and manages QDateTime properties.
  1543. A date and time property has a current value which can be
  1544. retrieved using the value() function, and set using the setValue()
  1545. slot. In addition, QtDateTimePropertyManager provides the
  1546. valueChanged() signal which is emitted whenever a property created
  1547. by this manager changes.
  1548. \sa QtAbstractPropertyManager, QtDateTimeEditFactory, QtDatePropertyManager
  1549. */
  1550. /*!
  1551. \fn void QtDateTimePropertyManager::valueChanged(QtProperty *property, const QDateTime &value)
  1552. This signal is emitted whenever a property created by this manager
  1553. changes its value, passing a pointer to the \a property and the new
  1554. \a value as parameters.
  1555. */
  1556. /*!
  1557. Creates a manager with the given \a parent.
  1558. */
  1559. QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent)
  1560. : QtAbstractPropertyManager(parent), d_ptr(new QtDateTimePropertyManagerPrivate(this))
  1561. {
  1562. }
  1563. /*!
  1564. Destroys this manager, and all the properties it has created.
  1565. */
  1566. QtDateTimePropertyManager::~QtDateTimePropertyManager()
  1567. {
  1568. clear();
  1569. }
  1570. /*!
  1571. Returns the given \a property's value.
  1572. If the given \a property is not managed by this manager, this
  1573. function returns an invalid QDateTime object.
  1574. \sa setValue()
  1575. */
  1576. QDateTime QtDateTimePropertyManager::value(const QtProperty *property) const
  1577. {
  1578. return d_ptr->m_values.value(property, QDateTime());
  1579. }
  1580. /*!
  1581. \reimp
  1582. */
  1583. QString QtDateTimePropertyManager::valueText(const QtProperty *property) const
  1584. {
  1585. const QtDateTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  1586. if (it == d_ptr->m_values.constEnd())
  1587. return QString();
  1588. return it.value().toString(d_ptr->m_format);
  1589. }
  1590. /*!
  1591. \fn void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &value)
  1592. Sets the value of the given \a property to \a value.
  1593. \sa value(), valueChanged()
  1594. */
  1595. void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &val)
  1596. {
  1597. setSimpleValue<const QDateTime &, QDateTime, QtDateTimePropertyManager>(d_ptr->m_values, this,
  1598. &QtDateTimePropertyManager::propertyChanged,
  1599. &QtDateTimePropertyManager::valueChanged,
  1600. property, val);
  1601. }
  1602. /*!
  1603. \reimp
  1604. */
  1605. void QtDateTimePropertyManager::initializeProperty(QtProperty *property)
  1606. {
  1607. d_ptr->m_values[property] = QDateTime::currentDateTime();
  1608. }
  1609. /*!
  1610. \reimp
  1611. */
  1612. void QtDateTimePropertyManager::uninitializeProperty(QtProperty *property)
  1613. {
  1614. d_ptr->m_values.remove(property);
  1615. }
  1616. // QtKeySequencePropertyManager
  1617. class QtKeySequencePropertyManagerPrivate
  1618. {
  1619. QtKeySequencePropertyManager *q_ptr;
  1620. Q_DECLARE_PUBLIC(QtKeySequencePropertyManager)
  1621. public:
  1622. QString m_format;
  1623. typedef QMap<const QtProperty *, QKeySequence> PropertyValueMap;
  1624. PropertyValueMap m_values;
  1625. };
  1626. /*! \class QtKeySequencePropertyManager
  1627. \internal
  1628. \inmodule QtDesigner
  1629. \since 4.4
  1630. \brief The QtKeySequencePropertyManager provides and manages QKeySequence properties.
  1631. A key sequence's value can be retrieved using the value()
  1632. function, and set using the setValue() slot.
  1633. In addition, QtKeySequencePropertyManager provides the valueChanged() signal
  1634. which is emitted whenever a property created by this manager
  1635. changes.
  1636. \sa QtAbstractPropertyManager
  1637. */
  1638. /*!
  1639. \fn void QtKeySequencePropertyManager::valueChanged(QtProperty *property, const QKeySequence &value)
  1640. This signal is emitted whenever a property created by this manager
  1641. changes its value, passing a pointer to the \a property and the new
  1642. \a value as parameters.
  1643. */
  1644. /*!
  1645. Creates a manager with the given \a parent.
  1646. */
  1647. QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent)
  1648. : QtAbstractPropertyManager(parent), d_ptr(new QtKeySequencePropertyManagerPrivate)
  1649. {
  1650. d_ptr->q_ptr = this;
  1651. }
  1652. /*!
  1653. Destroys this manager, and all the properties it has created.
  1654. */
  1655. QtKeySequencePropertyManager::~QtKeySequencePropertyManager()
  1656. {
  1657. clear();
  1658. }
  1659. /*!
  1660. Returns the given \a property's value.
  1661. If the given \a property is not managed by this manager, this
  1662. function returns an empty QKeySequence object.
  1663. \sa setValue()
  1664. */
  1665. QKeySequence QtKeySequencePropertyManager::value(const QtProperty *property) const
  1666. {
  1667. return d_ptr->m_values.value(property, QKeySequence());
  1668. }
  1669. /*!
  1670. \reimp
  1671. */
  1672. QString QtKeySequencePropertyManager::valueText(const QtProperty *property) const
  1673. {
  1674. const QtKeySequencePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  1675. if (it == d_ptr->m_values.constEnd())
  1676. return QString();
  1677. return it.value().toString(QKeySequence::NativeText);
  1678. }
  1679. /*!
  1680. \fn void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &value)
  1681. Sets the value of the given \a property to \a value.
  1682. \sa value(), valueChanged()
  1683. */
  1684. void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &val)
  1685. {
  1686. setSimpleValue<const QKeySequence &, QKeySequence, QtKeySequencePropertyManager>(d_ptr->m_values, this,
  1687. &QtKeySequencePropertyManager::propertyChanged,
  1688. &QtKeySequencePropertyManager::valueChanged,
  1689. property, val);
  1690. }
  1691. /*!
  1692. \reimp
  1693. */
  1694. void QtKeySequencePropertyManager::initializeProperty(QtProperty *property)
  1695. {
  1696. d_ptr->m_values[property] = QKeySequence();
  1697. }
  1698. /*!
  1699. \reimp
  1700. */
  1701. void QtKeySequencePropertyManager::uninitializeProperty(QtProperty *property)
  1702. {
  1703. d_ptr->m_values.remove(property);
  1704. }
  1705. // QtCharPropertyManager
  1706. class QtCharPropertyManagerPrivate
  1707. {
  1708. QtCharPropertyManager *q_ptr;
  1709. Q_DECLARE_PUBLIC(QtCharPropertyManager)
  1710. public:
  1711. typedef QMap<const QtProperty *, QChar> PropertyValueMap;
  1712. PropertyValueMap m_values;
  1713. };
  1714. /*! \class QtCharPropertyManager
  1715. \internal
  1716. \inmodule QtDesigner
  1717. \since 4.4
  1718. \brief The QtCharPropertyManager provides and manages QChar properties.
  1719. A char's value can be retrieved using the value()
  1720. function, and set using the setValue() slot.
  1721. In addition, QtCharPropertyManager provides the valueChanged() signal
  1722. which is emitted whenever a property created by this manager
  1723. changes.
  1724. \sa QtAbstractPropertyManager
  1725. */
  1726. /*!
  1727. \fn void QtCharPropertyManager::valueChanged(QtProperty *property, const QChar &value)
  1728. This signal is emitted whenever a property created by this manager
  1729. changes its value, passing a pointer to the \a property and the new
  1730. \a value as parameters.
  1731. */
  1732. /*!
  1733. Creates a manager with the given \a parent.
  1734. */
  1735. QtCharPropertyManager::QtCharPropertyManager(QObject *parent)
  1736. : QtAbstractPropertyManager(parent), d_ptr(new QtCharPropertyManagerPrivate)
  1737. {
  1738. d_ptr->q_ptr = this;
  1739. }
  1740. /*!
  1741. Destroys this manager, and all the properties it has created.
  1742. */
  1743. QtCharPropertyManager::~QtCharPropertyManager()
  1744. {
  1745. clear();
  1746. }
  1747. /*!
  1748. Returns the given \a property's value.
  1749. If the given \a property is not managed by this manager, this
  1750. function returns an null QChar object.
  1751. \sa setValue()
  1752. */
  1753. QChar QtCharPropertyManager::value(const QtProperty *property) const
  1754. {
  1755. return d_ptr->m_values.value(property, QChar());
  1756. }
  1757. /*!
  1758. \reimp
  1759. */
  1760. QString QtCharPropertyManager::valueText(const QtProperty *property) const
  1761. {
  1762. const QtCharPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  1763. if (it == d_ptr->m_values.constEnd())
  1764. return QString();
  1765. const QChar c = it.value();
  1766. return c.isNull() ? QString() : QString(c);
  1767. }
  1768. /*!
  1769. \fn void QtCharPropertyManager::setValue(QtProperty *property, const QChar &value)
  1770. Sets the value of the given \a property to \a value.
  1771. \sa value(), valueChanged()
  1772. */
  1773. void QtCharPropertyManager::setValue(QtProperty *property, const QChar &val)
  1774. {
  1775. setSimpleValue<const QChar &, QChar, QtCharPropertyManager>(d_ptr->m_values, this,
  1776. &QtCharPropertyManager::propertyChanged,
  1777. &QtCharPropertyManager::valueChanged,
  1778. property, val);
  1779. }
  1780. /*!
  1781. \reimp
  1782. */
  1783. void QtCharPropertyManager::initializeProperty(QtProperty *property)
  1784. {
  1785. d_ptr->m_values[property] = QChar();
  1786. }
  1787. /*!
  1788. \reimp
  1789. */
  1790. void QtCharPropertyManager::uninitializeProperty(QtProperty *property)
  1791. {
  1792. d_ptr->m_values.remove(property);
  1793. }
  1794. // QtLocalePropertyManager
  1795. class QtLocalePropertyManagerPrivate
  1796. {
  1797. QtLocalePropertyManager *q_ptr;
  1798. Q_DECLARE_PUBLIC(QtLocalePropertyManager)
  1799. public:
  1800. QtLocalePropertyManagerPrivate();
  1801. void slotEnumChanged(QtProperty *property, int value);
  1802. void slotPropertyDestroyed(QtProperty *property);
  1803. typedef QMap<const QtProperty *, QLocale> PropertyValueMap;
  1804. PropertyValueMap m_values;
  1805. QtEnumPropertyManager *m_enumPropertyManager;
  1806. QMap<const QtProperty *, QtProperty *> m_propertyToLanguage;
  1807. QMap<const QtProperty *, QtProperty *> m_propertyToCountry;
  1808. QMap<const QtProperty *, QtProperty *> m_languageToProperty;
  1809. QMap<const QtProperty *, QtProperty *> m_countryToProperty;
  1810. };
  1811. QtLocalePropertyManagerPrivate::QtLocalePropertyManagerPrivate()
  1812. {
  1813. }
  1814. void QtLocalePropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
  1815. {
  1816. if (QtProperty *prop = m_languageToProperty.value(property, 0)) {
  1817. const QLocale loc = m_values[prop];
  1818. QLocale::Language newLanguage = loc.language();
  1819. QLocale::Country newCountry = loc.country();
  1820. metaEnumProvider()->indexToLocale(value, 0, &newLanguage, 0);
  1821. QLocale newLoc(newLanguage, newCountry);
  1822. q_ptr->setValue(prop, newLoc);
  1823. } else if (QtProperty *prop = m_countryToProperty.value(property, 0)) {
  1824. const QLocale loc = m_values[prop];
  1825. QLocale::Language newLanguage = loc.language();
  1826. QLocale::Country newCountry = loc.country();
  1827. metaEnumProvider()->indexToLocale(m_enumPropertyManager->value(m_propertyToLanguage.value(prop)), value, &newLanguage, &newCountry);
  1828. QLocale newLoc(newLanguage, newCountry);
  1829. q_ptr->setValue(prop, newLoc);
  1830. }
  1831. }
  1832. void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
  1833. {
  1834. if (QtProperty *subProp = m_languageToProperty.value(property, 0)) {
  1835. m_propertyToLanguage[subProp] = 0;
  1836. m_languageToProperty.remove(property);
  1837. } else if (QtProperty *subProp = m_countryToProperty.value(property, 0)) {
  1838. m_propertyToCountry[subProp] = 0;
  1839. m_countryToProperty.remove(property);
  1840. }
  1841. }
  1842. /*!
  1843. \class QtLocalePropertyManager
  1844. \internal
  1845. \inmodule QtDesigner
  1846. \since 4.4
  1847. \brief The QtLocalePropertyManager provides and manages QLocale properties.
  1848. A locale property has nested \e language and \e country
  1849. subproperties. The top-level property's value can be retrieved
  1850. using the value() function, and set using the setValue() slot.
  1851. The subproperties are created by QtEnumPropertyManager object.
  1852. These submanager can be retrieved using the subEnumPropertyManager()
  1853. function. In order to provide editing widgets for the subproperties
  1854. in a property browser widget, this manager must be associated with editor factory.
  1855. In addition, QtLocalePropertyManager provides the valueChanged()
  1856. signal which is emitted whenever a property created by this
  1857. manager changes.
  1858. \sa QtAbstractPropertyManager, QtEnumPropertyManager
  1859. */
  1860. /*!
  1861. \fn void QtLocalePropertyManager::valueChanged(QtProperty *property, const QLocale &value)
  1862. This signal is emitted whenever a property created by this manager
  1863. changes its value, passing a pointer to the \a property and the
  1864. new \a value as parameters.
  1865. \sa setValue()
  1866. */
  1867. /*!
  1868. Creates a manager with the given \a parent.
  1869. */
  1870. QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent)
  1871. : QtAbstractPropertyManager(parent), d_ptr(new QtLocalePropertyManagerPrivate)
  1872. {
  1873. d_ptr->q_ptr = this;
  1874. d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
  1875. connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  1876. this, SLOT(slotEnumChanged(QtProperty*,int)));
  1877. connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  1878. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  1879. }
  1880. /*!
  1881. Destroys this manager, and all the properties it has created.
  1882. */
  1883. QtLocalePropertyManager::~QtLocalePropertyManager()
  1884. {
  1885. clear();
  1886. }
  1887. /*!
  1888. Returns the manager that creates the nested \e language
  1889. and \e country subproperties.
  1890. In order to provide editing widgets for the mentioned subproperties
  1891. in a property browser widget, this manager must be associated with
  1892. an editor factory.
  1893. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  1894. */
  1895. QtEnumPropertyManager *QtLocalePropertyManager::subEnumPropertyManager() const
  1896. {
  1897. return d_ptr->m_enumPropertyManager;
  1898. }
  1899. /*!
  1900. Returns the given \a property's value.
  1901. If the given property is not managed by this manager, this
  1902. function returns the default locale.
  1903. \sa setValue()
  1904. */
  1905. QLocale QtLocalePropertyManager::value(const QtProperty *property) const
  1906. {
  1907. return d_ptr->m_values.value(property, QLocale());
  1908. }
  1909. /*!
  1910. \reimp
  1911. */
  1912. QString QtLocalePropertyManager::valueText(const QtProperty *property) const
  1913. {
  1914. const QtLocalePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  1915. if (it == d_ptr->m_values.constEnd())
  1916. return QString();
  1917. const QLocale loc = it.value();
  1918. int langIdx = 0;
  1919. int countryIdx = 0;
  1920. const QtMetaEnumProvider *me = metaEnumProvider();
  1921. me->localeToIndex(loc.language(), loc.country(), &langIdx, &countryIdx);
  1922. if (langIdx < 0) {
  1923. qWarning("QtLocalePropertyManager::valueText: Unknown language %d", loc.language());
  1924. return tr("<Invalid>");
  1925. }
  1926. const QString languageName = me->languageEnumNames().at(langIdx);
  1927. if (countryIdx < 0) {
  1928. qWarning("QtLocalePropertyManager::valueText: Unknown country %d for %s", loc.country(), qPrintable(languageName));
  1929. return languageName;
  1930. }
  1931. const QString countryName = me->countryEnumNames(loc.language()).at(countryIdx);
  1932. return tr("%1, %2").arg(languageName, countryName);
  1933. }
  1934. /*!
  1935. \fn void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &value)
  1936. Sets the value of the given \a property to \a value. Nested
  1937. properties are updated automatically.
  1938. \sa value(), valueChanged()
  1939. */
  1940. void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &val)
  1941. {
  1942. const QtLocalePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  1943. if (it == d_ptr->m_values.end())
  1944. return;
  1945. const QLocale loc = it.value();
  1946. if (loc == val)
  1947. return;
  1948. it.value() = val;
  1949. int langIdx = 0;
  1950. int countryIdx = 0;
  1951. metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
  1952. if (loc.language() != val.language()) {
  1953. d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToLanguage.value(property), langIdx);
  1954. d_ptr->m_enumPropertyManager->setEnumNames(d_ptr->m_propertyToCountry.value(property),
  1955. metaEnumProvider()->countryEnumNames(val.language()));
  1956. }
  1957. d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToCountry.value(property), countryIdx);
  1958. emit propertyChanged(property);
  1959. emit valueChanged(property, val);
  1960. }
  1961. /*!
  1962. \reimp
  1963. */
  1964. void QtLocalePropertyManager::initializeProperty(QtProperty *property)
  1965. {
  1966. QLocale val;
  1967. d_ptr->m_values[property] = val;
  1968. int langIdx = 0;
  1969. int countryIdx = 0;
  1970. metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
  1971. QtProperty *languageProp = d_ptr->m_enumPropertyManager->addProperty();
  1972. languageProp->setPropertyName(tr("Language"));
  1973. d_ptr->m_enumPropertyManager->setEnumNames(languageProp, metaEnumProvider()->languageEnumNames());
  1974. d_ptr->m_enumPropertyManager->setValue(languageProp, langIdx);
  1975. d_ptr->m_propertyToLanguage[property] = languageProp;
  1976. d_ptr->m_languageToProperty[languageProp] = property;
  1977. property->addSubProperty(languageProp);
  1978. QtProperty *countryProp = d_ptr->m_enumPropertyManager->addProperty();
  1979. countryProp->setPropertyName(tr("Country"));
  1980. d_ptr->m_enumPropertyManager->setEnumNames(countryProp, metaEnumProvider()->countryEnumNames(val.language()));
  1981. d_ptr->m_enumPropertyManager->setValue(countryProp, countryIdx);
  1982. d_ptr->m_propertyToCountry[property] = countryProp;
  1983. d_ptr->m_countryToProperty[countryProp] = property;
  1984. property->addSubProperty(countryProp);
  1985. }
  1986. /*!
  1987. \reimp
  1988. */
  1989. void QtLocalePropertyManager::uninitializeProperty(QtProperty *property)
  1990. {
  1991. QtProperty *languageProp = d_ptr->m_propertyToLanguage[property];
  1992. if (languageProp) {
  1993. d_ptr->m_languageToProperty.remove(languageProp);
  1994. delete languageProp;
  1995. }
  1996. d_ptr->m_propertyToLanguage.remove(property);
  1997. QtProperty *countryProp = d_ptr->m_propertyToCountry[property];
  1998. if (countryProp) {
  1999. d_ptr->m_countryToProperty.remove(countryProp);
  2000. delete countryProp;
  2001. }
  2002. d_ptr->m_propertyToCountry.remove(property);
  2003. d_ptr->m_values.remove(property);
  2004. }
  2005. // QtPointPropertyManager
  2006. class QtPointPropertyManagerPrivate
  2007. {
  2008. QtPointPropertyManager *q_ptr;
  2009. Q_DECLARE_PUBLIC(QtPointPropertyManager)
  2010. public:
  2011. void slotIntChanged(QtProperty *property, int value);
  2012. void slotPropertyDestroyed(QtProperty *property);
  2013. typedef QMap<const QtProperty *, QPoint> PropertyValueMap;
  2014. PropertyValueMap m_values;
  2015. QtIntPropertyManager *m_intPropertyManager;
  2016. QMap<const QtProperty *, QtProperty *> m_propertyToX;
  2017. QMap<const QtProperty *, QtProperty *> m_propertyToY;
  2018. QMap<const QtProperty *, QtProperty *> m_xToProperty;
  2019. QMap<const QtProperty *, QtProperty *> m_yToProperty;
  2020. };
  2021. void QtPointPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
  2022. {
  2023. if (QtProperty *xprop = m_xToProperty.value(property, 0)) {
  2024. QPoint p = m_values[xprop];
  2025. p.setX(value);
  2026. q_ptr->setValue(xprop, p);
  2027. } else if (QtProperty *yprop = m_yToProperty.value(property, 0)) {
  2028. QPoint p = m_values[yprop];
  2029. p.setY(value);
  2030. q_ptr->setValue(yprop, p);
  2031. }
  2032. }
  2033. void QtPointPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
  2034. {
  2035. if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
  2036. m_propertyToX[pointProp] = 0;
  2037. m_xToProperty.remove(property);
  2038. } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
  2039. m_propertyToY[pointProp] = 0;
  2040. m_yToProperty.remove(property);
  2041. }
  2042. }
  2043. /*! \class QtPointPropertyManager
  2044. \internal
  2045. \inmodule QtDesigner
  2046. \since 4.4
  2047. \brief The QtPointPropertyManager provides and manages QPoint properties.
  2048. A point property has nested \e x and \e y subproperties. The
  2049. top-level property's value can be retrieved using the value()
  2050. function, and set using the setValue() slot.
  2051. The subproperties are created by a QtIntPropertyManager object. This
  2052. manager can be retrieved using the subIntPropertyManager() function. In
  2053. order to provide editing widgets for the subproperties in a
  2054. property browser widget, this manager must be associated with an
  2055. editor factory.
  2056. In addition, QtPointPropertyManager provides the valueChanged() signal which
  2057. is emitted whenever a property created by this manager changes.
  2058. \sa QtAbstractPropertyManager, QtIntPropertyManager, QtPointFPropertyManager
  2059. */
  2060. /*!
  2061. \fn void QtPointPropertyManager::valueChanged(QtProperty *property, const QPoint &value)
  2062. This signal is emitted whenever a property created by this manager
  2063. changes its value, passing a pointer to the \a property and the
  2064. new \a value as parameters.
  2065. \sa setValue()
  2066. */
  2067. /*!
  2068. Creates a manager with the given \a parent.
  2069. */
  2070. QtPointPropertyManager::QtPointPropertyManager(QObject *parent)
  2071. : QtAbstractPropertyManager(parent), d_ptr(new QtPointPropertyManagerPrivate)
  2072. {
  2073. d_ptr->q_ptr = this;
  2074. d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
  2075. connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  2076. this, SLOT(slotIntChanged(QtProperty*,int)));
  2077. connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  2078. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  2079. }
  2080. /*!
  2081. Destroys this manager, and all the properties it has created.
  2082. */
  2083. QtPointPropertyManager::~QtPointPropertyManager()
  2084. {
  2085. clear();
  2086. }
  2087. /*!
  2088. Returns the manager that creates the nested \e x and \e y
  2089. subproperties.
  2090. In order to provide editing widgets for the subproperties in a
  2091. property browser widget, this manager must be associated with an
  2092. editor factory.
  2093. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  2094. */
  2095. QtIntPropertyManager *QtPointPropertyManager::subIntPropertyManager() const
  2096. {
  2097. return d_ptr->m_intPropertyManager;
  2098. }
  2099. /*!
  2100. Returns the given \a property's value.
  2101. If the given \a property is not managed by this manager, this
  2102. function returns a point with coordinates (0, 0).
  2103. \sa setValue()
  2104. */
  2105. QPoint QtPointPropertyManager::value(const QtProperty *property) const
  2106. {
  2107. return d_ptr->m_values.value(property, QPoint());
  2108. }
  2109. /*!
  2110. \reimp
  2111. */
  2112. QString QtPointPropertyManager::valueText(const QtProperty *property) const
  2113. {
  2114. const QtPointPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  2115. if (it == d_ptr->m_values.constEnd())
  2116. return QString();
  2117. const QPoint v = it.value();
  2118. return tr("(%1, %2)").arg(QString::number(v.x()))
  2119. .arg(QString::number(v.y()));
  2120. }
  2121. /*!
  2122. \fn void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &value)
  2123. Sets the value of the given \a property to \a value. Nested
  2124. properties are updated automatically.
  2125. \sa value(), valueChanged()
  2126. */
  2127. void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &val)
  2128. {
  2129. const QtPointPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  2130. if (it == d_ptr->m_values.end())
  2131. return;
  2132. if (it.value() == val)
  2133. return;
  2134. it.value() = val;
  2135. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
  2136. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
  2137. emit propertyChanged(property);
  2138. emit valueChanged(property, val);
  2139. }
  2140. /*!
  2141. \reimp
  2142. */
  2143. void QtPointPropertyManager::initializeProperty(QtProperty *property)
  2144. {
  2145. d_ptr->m_values[property] = QPoint(0, 0);
  2146. QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
  2147. xProp->setPropertyName(tr("X"));
  2148. d_ptr->m_intPropertyManager->setValue(xProp, 0);
  2149. d_ptr->m_propertyToX[property] = xProp;
  2150. d_ptr->m_xToProperty[xProp] = property;
  2151. property->addSubProperty(xProp);
  2152. QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
  2153. yProp->setPropertyName(tr("Y"));
  2154. d_ptr->m_intPropertyManager->setValue(yProp, 0);
  2155. d_ptr->m_propertyToY[property] = yProp;
  2156. d_ptr->m_yToProperty[yProp] = property;
  2157. property->addSubProperty(yProp);
  2158. }
  2159. /*!
  2160. \reimp
  2161. */
  2162. void QtPointPropertyManager::uninitializeProperty(QtProperty *property)
  2163. {
  2164. QtProperty *xProp = d_ptr->m_propertyToX[property];
  2165. if (xProp) {
  2166. d_ptr->m_xToProperty.remove(xProp);
  2167. delete xProp;
  2168. }
  2169. d_ptr->m_propertyToX.remove(property);
  2170. QtProperty *yProp = d_ptr->m_propertyToY[property];
  2171. if (yProp) {
  2172. d_ptr->m_yToProperty.remove(yProp);
  2173. delete yProp;
  2174. }
  2175. d_ptr->m_propertyToY.remove(property);
  2176. d_ptr->m_values.remove(property);
  2177. }
  2178. // QtPointFPropertyManager
  2179. class QtPointFPropertyManagerPrivate
  2180. {
  2181. QtPointFPropertyManager *q_ptr;
  2182. Q_DECLARE_PUBLIC(QtPointFPropertyManager)
  2183. public:
  2184. struct Data
  2185. {
  2186. QPointF val;
  2187. int decimals{2};
  2188. };
  2189. void slotDoubleChanged(QtProperty *property, double value);
  2190. void slotPropertyDestroyed(QtProperty *property);
  2191. typedef QMap<const QtProperty *, Data> PropertyValueMap;
  2192. PropertyValueMap m_values;
  2193. QtDoublePropertyManager *m_doublePropertyManager;
  2194. QMap<const QtProperty *, QtProperty *> m_propertyToX;
  2195. QMap<const QtProperty *, QtProperty *> m_propertyToY;
  2196. QMap<const QtProperty *, QtProperty *> m_xToProperty;
  2197. QMap<const QtProperty *, QtProperty *> m_yToProperty;
  2198. };
  2199. void QtPointFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
  2200. {
  2201. if (QtProperty *prop = m_xToProperty.value(property, 0)) {
  2202. QPointF p = m_values[prop].val;
  2203. p.setX(value);
  2204. q_ptr->setValue(prop, p);
  2205. } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
  2206. QPointF p = m_values[prop].val;
  2207. p.setY(value);
  2208. q_ptr->setValue(prop, p);
  2209. }
  2210. }
  2211. void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
  2212. {
  2213. if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
  2214. m_propertyToX[pointProp] = 0;
  2215. m_xToProperty.remove(property);
  2216. } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
  2217. m_propertyToY[pointProp] = 0;
  2218. m_yToProperty.remove(property);
  2219. }
  2220. }
  2221. /*! \class QtPointFPropertyManager
  2222. \internal
  2223. \inmodule QtDesigner
  2224. \since 4.4
  2225. \brief The QtPointFPropertyManager provides and manages QPointF properties.
  2226. A point property has nested \e x and \e y subproperties. The
  2227. top-level property's value can be retrieved using the value()
  2228. function, and set using the setValue() slot.
  2229. The subproperties are created by a QtDoublePropertyManager object. This
  2230. manager can be retrieved using the subDoublePropertyManager() function. In
  2231. order to provide editing widgets for the subproperties in a
  2232. property browser widget, this manager must be associated with an
  2233. editor factory.
  2234. In addition, QtPointFPropertyManager provides the valueChanged() signal which
  2235. is emitted whenever a property created by this manager changes.
  2236. \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtPointPropertyManager
  2237. */
  2238. /*!
  2239. \fn void QtPointFPropertyManager::valueChanged(QtProperty *property, const QPointF &value)
  2240. This signal is emitted whenever a property created by this manager
  2241. changes its value, passing a pointer to the \a property and the
  2242. new \a value as parameters.
  2243. \sa setValue()
  2244. */
  2245. /*!
  2246. \fn void QtPointFPropertyManager::decimalsChanged(QtProperty *property, int prec)
  2247. This signal is emitted whenever a property created by this manager
  2248. changes its precision of value, passing a pointer to the
  2249. \a property and the new \a prec value
  2250. \sa setDecimals()
  2251. */
  2252. /*!
  2253. Creates a manager with the given \a parent.
  2254. */
  2255. QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent)
  2256. : QtAbstractPropertyManager(parent), d_ptr(new QtPointFPropertyManagerPrivate)
  2257. {
  2258. d_ptr->q_ptr = this;
  2259. d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
  2260. connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
  2261. this, SLOT(slotDoubleChanged(QtProperty*,double)));
  2262. connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  2263. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  2264. }
  2265. /*!
  2266. Destroys this manager, and all the properties it has created.
  2267. */
  2268. QtPointFPropertyManager::~QtPointFPropertyManager()
  2269. {
  2270. clear();
  2271. }
  2272. /*!
  2273. Returns the manager that creates the nested \e x and \e y
  2274. subproperties.
  2275. In order to provide editing widgets for the subproperties in a
  2276. property browser widget, this manager must be associated with an
  2277. editor factory.
  2278. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  2279. */
  2280. QtDoublePropertyManager *QtPointFPropertyManager::subDoublePropertyManager() const
  2281. {
  2282. return d_ptr->m_doublePropertyManager;
  2283. }
  2284. /*!
  2285. Returns the given \a property's value.
  2286. If the given \a property is not managed by this manager, this
  2287. function returns a point with coordinates (0, 0).
  2288. \sa setValue()
  2289. */
  2290. QPointF QtPointFPropertyManager::value(const QtProperty *property) const
  2291. {
  2292. return getValue<QPointF>(d_ptr->m_values, property);
  2293. }
  2294. /*!
  2295. Returns the given \a property's precision, in decimals.
  2296. \sa setDecimals()
  2297. */
  2298. int QtPointFPropertyManager::decimals(const QtProperty *property) const
  2299. {
  2300. return getData<int>(d_ptr->m_values, &QtPointFPropertyManagerPrivate::Data::decimals, property, 0);
  2301. }
  2302. /*!
  2303. \reimp
  2304. */
  2305. QString QtPointFPropertyManager::valueText(const QtProperty *property) const
  2306. {
  2307. const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  2308. if (it == d_ptr->m_values.constEnd())
  2309. return QString();
  2310. const QPointF v = it.value().val;
  2311. const int dec = it.value().decimals;
  2312. return tr("(%1, %2)").arg(QString::number(v.x(), 'f', dec))
  2313. .arg(QString::number(v.y(), 'f', dec));
  2314. }
  2315. /*!
  2316. \fn void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &value)
  2317. Sets the value of the given \a property to \a value. Nested
  2318. properties are updated automatically.
  2319. \sa value(), valueChanged()
  2320. */
  2321. void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &val)
  2322. {
  2323. const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  2324. if (it == d_ptr->m_values.end())
  2325. return;
  2326. if (it.value().val == val)
  2327. return;
  2328. it.value().val = val;
  2329. d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
  2330. d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
  2331. emit propertyChanged(property);
  2332. emit valueChanged(property, val);
  2333. }
  2334. /*!
  2335. \fn void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
  2336. Sets the precision of the given \a property to \a prec.
  2337. The valid decimal range is 0-13. The default is 2.
  2338. \sa decimals()
  2339. */
  2340. void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
  2341. {
  2342. const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  2343. if (it == d_ptr->m_values.end())
  2344. return;
  2345. QtPointFPropertyManagerPrivate::Data data = it.value();
  2346. if (prec > 13)
  2347. prec = 13;
  2348. else if (prec < 0)
  2349. prec = 0;
  2350. if (data.decimals == prec)
  2351. return;
  2352. data.decimals = prec;
  2353. d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
  2354. d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
  2355. it.value() = data;
  2356. emit decimalsChanged(property, data.decimals);
  2357. }
  2358. /*!
  2359. \reimp
  2360. */
  2361. void QtPointFPropertyManager::initializeProperty(QtProperty *property)
  2362. {
  2363. d_ptr->m_values[property] = QtPointFPropertyManagerPrivate::Data();
  2364. QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
  2365. xProp->setPropertyName(tr("X"));
  2366. d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
  2367. d_ptr->m_doublePropertyManager->setValue(xProp, 0);
  2368. d_ptr->m_propertyToX[property] = xProp;
  2369. d_ptr->m_xToProperty[xProp] = property;
  2370. property->addSubProperty(xProp);
  2371. QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
  2372. yProp->setPropertyName(tr("Y"));
  2373. d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
  2374. d_ptr->m_doublePropertyManager->setValue(yProp, 0);
  2375. d_ptr->m_propertyToY[property] = yProp;
  2376. d_ptr->m_yToProperty[yProp] = property;
  2377. property->addSubProperty(yProp);
  2378. }
  2379. /*!
  2380. \reimp
  2381. */
  2382. void QtPointFPropertyManager::uninitializeProperty(QtProperty *property)
  2383. {
  2384. QtProperty *xProp = d_ptr->m_propertyToX[property];
  2385. if (xProp) {
  2386. d_ptr->m_xToProperty.remove(xProp);
  2387. delete xProp;
  2388. }
  2389. d_ptr->m_propertyToX.remove(property);
  2390. QtProperty *yProp = d_ptr->m_propertyToY[property];
  2391. if (yProp) {
  2392. d_ptr->m_yToProperty.remove(yProp);
  2393. delete yProp;
  2394. }
  2395. d_ptr->m_propertyToY.remove(property);
  2396. d_ptr->m_values.remove(property);
  2397. }
  2398. // QtSizePropertyManager
  2399. class QtSizePropertyManagerPrivate
  2400. {
  2401. QtSizePropertyManager *q_ptr;
  2402. Q_DECLARE_PUBLIC(QtSizePropertyManager)
  2403. public:
  2404. void slotIntChanged(QtProperty *property, int value);
  2405. void slotPropertyDestroyed(QtProperty *property);
  2406. void setValue(QtProperty *property, const QSize &val);
  2407. void setRange(QtProperty *property,
  2408. const QSize &minVal, const QSize &maxVal, const QSize &val);
  2409. struct Data
  2410. {
  2411. QSize val{0, 0};
  2412. QSize minVal{0, 0};
  2413. QSize maxVal{INT_MAX, INT_MAX};
  2414. QSize minimumValue() const { return minVal; }
  2415. QSize maximumValue() const { return maxVal; }
  2416. void setMinimumValue(const QSize &newMinVal) { setSizeMinimumData(this, newMinVal); }
  2417. void setMaximumValue(const QSize &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
  2418. };
  2419. typedef QMap<const QtProperty *, Data> PropertyValueMap;
  2420. PropertyValueMap m_values;
  2421. QtIntPropertyManager *m_intPropertyManager;
  2422. QMap<const QtProperty *, QtProperty *> m_propertyToW;
  2423. QMap<const QtProperty *, QtProperty *> m_propertyToH;
  2424. QMap<const QtProperty *, QtProperty *> m_wToProperty;
  2425. QMap<const QtProperty *, QtProperty *> m_hToProperty;
  2426. };
  2427. void QtSizePropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
  2428. {
  2429. if (QtProperty *prop = m_wToProperty.value(property, 0)) {
  2430. QSize s = m_values[prop].val;
  2431. s.setWidth(value);
  2432. q_ptr->setValue(prop, s);
  2433. } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
  2434. QSize s = m_values[prop].val;
  2435. s.setHeight(value);
  2436. q_ptr->setValue(prop, s);
  2437. }
  2438. }
  2439. void QtSizePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
  2440. {
  2441. if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
  2442. m_propertyToW[pointProp] = 0;
  2443. m_wToProperty.remove(property);
  2444. } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
  2445. m_propertyToH[pointProp] = 0;
  2446. m_hToProperty.remove(property);
  2447. }
  2448. }
  2449. void QtSizePropertyManagerPrivate::setValue(QtProperty *property, const QSize &val)
  2450. {
  2451. m_intPropertyManager->setValue(m_propertyToW.value(property), val.width());
  2452. m_intPropertyManager->setValue(m_propertyToH.value(property), val.height());
  2453. }
  2454. void QtSizePropertyManagerPrivate::setRange(QtProperty *property,
  2455. const QSize &minVal, const QSize &maxVal, const QSize &val)
  2456. {
  2457. QtProperty *wProperty = m_propertyToW.value(property);
  2458. QtProperty *hProperty = m_propertyToH.value(property);
  2459. m_intPropertyManager->setRange(wProperty, minVal.width(), maxVal.width());
  2460. m_intPropertyManager->setValue(wProperty, val.width());
  2461. m_intPropertyManager->setRange(hProperty, minVal.height(), maxVal.height());
  2462. m_intPropertyManager->setValue(hProperty, val.height());
  2463. }
  2464. /*!
  2465. \class QtSizePropertyManager
  2466. \internal
  2467. \inmodule QtDesigner
  2468. \since 4.4
  2469. \brief The QtSizePropertyManager provides and manages QSize properties.
  2470. A size property has nested \e width and \e height
  2471. subproperties. The top-level property's value can be retrieved
  2472. using the value() function, and set using the setValue() slot.
  2473. The subproperties are created by a QtIntPropertyManager object. This
  2474. manager can be retrieved using the subIntPropertyManager() function. In
  2475. order to provide editing widgets for the subproperties in a
  2476. property browser widget, this manager must be associated with an
  2477. editor factory.
  2478. A size property also has a range of valid values defined by a
  2479. minimum size and a maximum size. These sizes can be retrieved
  2480. using the minimum() and the maximum() functions, and set using the
  2481. setMinimum() and setMaximum() slots. Alternatively, the range can
  2482. be defined in one go using the setRange() slot.
  2483. In addition, QtSizePropertyManager provides the valueChanged() signal
  2484. which is emitted whenever a property created by this manager
  2485. changes, and the rangeChanged() signal which is emitted whenever
  2486. such a property changes its range of valid sizes.
  2487. \sa QtAbstractPropertyManager, QtIntPropertyManager, QtSizeFPropertyManager
  2488. */
  2489. /*!
  2490. \fn void QtSizePropertyManager::valueChanged(QtProperty *property, const QSize &value)
  2491. This signal is emitted whenever a property created by this manager
  2492. changes its value, passing a pointer to the \a property and the new
  2493. \a value as parameters.
  2494. \sa setValue()
  2495. */
  2496. /*!
  2497. \fn void QtSizePropertyManager::rangeChanged(QtProperty *property, const QSize &minimum, const QSize &maximum)
  2498. This signal is emitted whenever a property created by this manager
  2499. changes its range of valid sizes, passing a pointer to the \a
  2500. property and the new \a minimum and \a maximum sizes.
  2501. \sa setRange()
  2502. */
  2503. /*!
  2504. Creates a manager with the given \a parent.
  2505. */
  2506. QtSizePropertyManager::QtSizePropertyManager(QObject *parent)
  2507. : QtAbstractPropertyManager(parent), d_ptr(new QtSizePropertyManagerPrivate)
  2508. {
  2509. d_ptr->q_ptr = this;
  2510. d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
  2511. connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  2512. this, SLOT(slotIntChanged(QtProperty*,int)));
  2513. connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  2514. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  2515. }
  2516. /*!
  2517. Destroys this manager, and all the properties it has created.
  2518. */
  2519. QtSizePropertyManager::~QtSizePropertyManager()
  2520. {
  2521. clear();
  2522. }
  2523. /*!
  2524. Returns the manager that creates the nested \e width and \e height
  2525. subproperties.
  2526. In order to provide editing widgets for the \e width and \e height
  2527. properties in a property browser widget, this manager must be
  2528. associated with an editor factory.
  2529. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  2530. */
  2531. QtIntPropertyManager *QtSizePropertyManager::subIntPropertyManager() const
  2532. {
  2533. return d_ptr->m_intPropertyManager;
  2534. }
  2535. /*!
  2536. Returns the given \a property's value.
  2537. If the given \a property is not managed by this manager, this
  2538. function returns an invalid size
  2539. \sa setValue()
  2540. */
  2541. QSize QtSizePropertyManager::value(const QtProperty *property) const
  2542. {
  2543. return getValue<QSize>(d_ptr->m_values, property);
  2544. }
  2545. /*!
  2546. Returns the given \a property's minimum size value.
  2547. \sa setMinimum(), maximum(), setRange()
  2548. */
  2549. QSize QtSizePropertyManager::minimum(const QtProperty *property) const
  2550. {
  2551. return getMinimum<QSize>(d_ptr->m_values, property);
  2552. }
  2553. /*!
  2554. Returns the given \a property's maximum size value.
  2555. \sa setMaximum(), minimum(), setRange()
  2556. */
  2557. QSize QtSizePropertyManager::maximum(const QtProperty *property) const
  2558. {
  2559. return getMaximum<QSize>(d_ptr->m_values, property);
  2560. }
  2561. /*!
  2562. \reimp
  2563. */
  2564. QString QtSizePropertyManager::valueText(const QtProperty *property) const
  2565. {
  2566. const QtSizePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  2567. if (it == d_ptr->m_values.constEnd())
  2568. return QString();
  2569. const QSize v = it.value().val;
  2570. return tr("%1 x %2").arg(QString::number(v.width()))
  2571. .arg(QString::number(v.height()));
  2572. }
  2573. /*!
  2574. \fn void QtSizePropertyManager::setValue(QtProperty *property, const QSize &value)
  2575. Sets the value of the given \a property to \a value.
  2576. If the specified \a value is not valid according to the given \a
  2577. property's size range, the \a value is adjusted to the nearest
  2578. valid value within the size range.
  2579. \sa value(), setRange(), valueChanged()
  2580. */
  2581. void QtSizePropertyManager::setValue(QtProperty *property, const QSize &val)
  2582. {
  2583. setValueInRange<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, const QSize>(this, d_ptr.data(),
  2584. &QtSizePropertyManager::propertyChanged,
  2585. &QtSizePropertyManager::valueChanged,
  2586. property, val, &QtSizePropertyManagerPrivate::setValue);
  2587. }
  2588. /*!
  2589. Sets the minimum size value for the given \a property to \a minVal.
  2590. When setting the minimum size value, the maximum and current
  2591. values are adjusted if necessary (ensuring that the size range
  2592. remains valid and that the current value is within the range).
  2593. \sa minimum(), setRange(), rangeChanged()
  2594. */
  2595. void QtSizePropertyManager::setMinimum(QtProperty *property, const QSize &minVal)
  2596. {
  2597. setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr.data(),
  2598. &QtSizePropertyManager::propertyChanged,
  2599. &QtSizePropertyManager::valueChanged,
  2600. &QtSizePropertyManager::rangeChanged,
  2601. property,
  2602. &QtSizePropertyManagerPrivate::Data::minimumValue,
  2603. &QtSizePropertyManagerPrivate::Data::setMinimumValue,
  2604. minVal, &QtSizePropertyManagerPrivate::setRange);
  2605. }
  2606. /*!
  2607. Sets the maximum size value for the given \a property to \a maxVal.
  2608. When setting the maximum size value, the minimum and current
  2609. values are adjusted if necessary (ensuring that the size range
  2610. remains valid and that the current value is within the range).
  2611. \sa maximum(), setRange(), rangeChanged()
  2612. */
  2613. void QtSizePropertyManager::setMaximum(QtProperty *property, const QSize &maxVal)
  2614. {
  2615. setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr.data(),
  2616. &QtSizePropertyManager::propertyChanged,
  2617. &QtSizePropertyManager::valueChanged,
  2618. &QtSizePropertyManager::rangeChanged,
  2619. property,
  2620. &QtSizePropertyManagerPrivate::Data::maximumValue,
  2621. &QtSizePropertyManagerPrivate::Data::setMaximumValue,
  2622. maxVal, &QtSizePropertyManagerPrivate::setRange);
  2623. }
  2624. /*!
  2625. \fn void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minimum, const QSize &maximum)
  2626. Sets the range of valid values.
  2627. This is a convenience function defining the range of valid values
  2628. in one go; setting the \a minimum and \a maximum values for the
  2629. given \a property with a single function call.
  2630. When setting a new range, the current value is adjusted if
  2631. necessary (ensuring that the value remains within the range).
  2632. \sa setMinimum(), setMaximum(), rangeChanged()
  2633. */
  2634. void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minVal, const QSize &maxVal)
  2635. {
  2636. setBorderValues<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize>(this, d_ptr.data(),
  2637. &QtSizePropertyManager::propertyChanged,
  2638. &QtSizePropertyManager::valueChanged,
  2639. &QtSizePropertyManager::rangeChanged,
  2640. property, minVal, maxVal, &QtSizePropertyManagerPrivate::setRange);
  2641. }
  2642. /*!
  2643. \reimp
  2644. */
  2645. void QtSizePropertyManager::initializeProperty(QtProperty *property)
  2646. {
  2647. d_ptr->m_values[property] = QtSizePropertyManagerPrivate::Data();
  2648. QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
  2649. wProp->setPropertyName(tr("Width"));
  2650. d_ptr->m_intPropertyManager->setValue(wProp, 0);
  2651. d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
  2652. d_ptr->m_propertyToW[property] = wProp;
  2653. d_ptr->m_wToProperty[wProp] = property;
  2654. property->addSubProperty(wProp);
  2655. QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
  2656. hProp->setPropertyName(tr("Height"));
  2657. d_ptr->m_intPropertyManager->setValue(hProp, 0);
  2658. d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
  2659. d_ptr->m_propertyToH[property] = hProp;
  2660. d_ptr->m_hToProperty[hProp] = property;
  2661. property->addSubProperty(hProp);
  2662. }
  2663. /*!
  2664. \reimp
  2665. */
  2666. void QtSizePropertyManager::uninitializeProperty(QtProperty *property)
  2667. {
  2668. QtProperty *wProp = d_ptr->m_propertyToW[property];
  2669. if (wProp) {
  2670. d_ptr->m_wToProperty.remove(wProp);
  2671. delete wProp;
  2672. }
  2673. d_ptr->m_propertyToW.remove(property);
  2674. QtProperty *hProp = d_ptr->m_propertyToH[property];
  2675. if (hProp) {
  2676. d_ptr->m_hToProperty.remove(hProp);
  2677. delete hProp;
  2678. }
  2679. d_ptr->m_propertyToH.remove(property);
  2680. d_ptr->m_values.remove(property);
  2681. }
  2682. // QtSizeFPropertyManager
  2683. class QtSizeFPropertyManagerPrivate
  2684. {
  2685. QtSizeFPropertyManager *q_ptr;
  2686. Q_DECLARE_PUBLIC(QtSizeFPropertyManager)
  2687. public:
  2688. void slotDoubleChanged(QtProperty *property, double value);
  2689. void slotPropertyDestroyed(QtProperty *property);
  2690. void setValue(QtProperty *property, const QSizeF &val);
  2691. void setRange(QtProperty *property,
  2692. const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val);
  2693. struct Data
  2694. {
  2695. QSizeF val{0, 0};
  2696. QSizeF minVal{0, 0};
  2697. QSizeF maxVal{std::numeric_limits<qreal>::max(), std::numeric_limits<qreal>::max()};
  2698. int decimals{2};
  2699. QSizeF minimumValue() const { return minVal; }
  2700. QSizeF maximumValue() const { return maxVal; }
  2701. void setMinimumValue(const QSizeF &newMinVal) { setSizeMinimumData(this, newMinVal); }
  2702. void setMaximumValue(const QSizeF &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
  2703. };
  2704. typedef QMap<const QtProperty *, Data> PropertyValueMap;
  2705. PropertyValueMap m_values;
  2706. QtDoublePropertyManager *m_doublePropertyManager;
  2707. QMap<const QtProperty *, QtProperty *> m_propertyToW;
  2708. QMap<const QtProperty *, QtProperty *> m_propertyToH;
  2709. QMap<const QtProperty *, QtProperty *> m_wToProperty;
  2710. QMap<const QtProperty *, QtProperty *> m_hToProperty;
  2711. };
  2712. void QtSizeFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
  2713. {
  2714. if (QtProperty *prop = m_wToProperty.value(property, 0)) {
  2715. QSizeF s = m_values[prop].val;
  2716. s.setWidth(value);
  2717. q_ptr->setValue(prop, s);
  2718. } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
  2719. QSizeF s = m_values[prop].val;
  2720. s.setHeight(value);
  2721. q_ptr->setValue(prop, s);
  2722. }
  2723. }
  2724. void QtSizeFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
  2725. {
  2726. if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
  2727. m_propertyToW[pointProp] = 0;
  2728. m_wToProperty.remove(property);
  2729. } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
  2730. m_propertyToH[pointProp] = 0;
  2731. m_hToProperty.remove(property);
  2732. }
  2733. }
  2734. void QtSizeFPropertyManagerPrivate::setValue(QtProperty *property, const QSizeF &val)
  2735. {
  2736. m_doublePropertyManager->setValue(m_propertyToW.value(property), val.width());
  2737. m_doublePropertyManager->setValue(m_propertyToH.value(property), val.height());
  2738. }
  2739. void QtSizeFPropertyManagerPrivate::setRange(QtProperty *property,
  2740. const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val)
  2741. {
  2742. m_doublePropertyManager->setRange(m_propertyToW[property], minVal.width(), maxVal.width());
  2743. m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
  2744. m_doublePropertyManager->setRange(m_propertyToH[property], minVal.height(), maxVal.height());
  2745. m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
  2746. }
  2747. /*!
  2748. \class QtSizeFPropertyManager
  2749. \internal
  2750. \inmodule QtDesigner
  2751. \since 4.4
  2752. \brief The QtSizeFPropertyManager provides and manages QSizeF properties.
  2753. A size property has nested \e width and \e height
  2754. subproperties. The top-level property's value can be retrieved
  2755. using the value() function, and set using the setValue() slot.
  2756. The subproperties are created by a QtDoublePropertyManager object. This
  2757. manager can be retrieved using the subDoublePropertyManager() function. In
  2758. order to provide editing widgets for the subproperties in a
  2759. property browser widget, this manager must be associated with an
  2760. editor factory.
  2761. A size property also has a range of valid values defined by a
  2762. minimum size and a maximum size. These sizes can be retrieved
  2763. using the minimum() and the maximum() functions, and set using the
  2764. setMinimum() and setMaximum() slots. Alternatively, the range can
  2765. be defined in one go using the setRange() slot.
  2766. In addition, QtSizeFPropertyManager provides the valueChanged() signal
  2767. which is emitted whenever a property created by this manager
  2768. changes, and the rangeChanged() signal which is emitted whenever
  2769. such a property changes its range of valid sizes.
  2770. \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtSizePropertyManager
  2771. */
  2772. /*!
  2773. \fn void QtSizeFPropertyManager::valueChanged(QtProperty *property, const QSizeF &value)
  2774. This signal is emitted whenever a property created by this manager
  2775. changes its value, passing a pointer to the \a property and the new
  2776. \a value as parameters.
  2777. \sa setValue()
  2778. */
  2779. /*!
  2780. \fn void QtSizeFPropertyManager::rangeChanged(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
  2781. This signal is emitted whenever a property created by this manager
  2782. changes its range of valid sizes, passing a pointer to the \a
  2783. property and the new \a minimum and \a maximum sizes.
  2784. \sa setRange()
  2785. */
  2786. /*!
  2787. \fn void QtSizeFPropertyManager::decimalsChanged(QtProperty *property, int prec)
  2788. This signal is emitted whenever a property created by this manager
  2789. changes its precision of value, passing a pointer to the
  2790. \a property and the new \a prec value
  2791. \sa setDecimals()
  2792. */
  2793. /*!
  2794. Creates a manager with the given \a parent.
  2795. */
  2796. QtSizeFPropertyManager::QtSizeFPropertyManager(QObject *parent)
  2797. : QtAbstractPropertyManager(parent), d_ptr(new QtSizeFPropertyManagerPrivate)
  2798. {
  2799. d_ptr->q_ptr = this;
  2800. d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
  2801. connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
  2802. this, SLOT(slotDoubleChanged(QtProperty*,double)));
  2803. connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  2804. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  2805. }
  2806. /*!
  2807. Destroys this manager, and all the properties it has created.
  2808. */
  2809. QtSizeFPropertyManager::~QtSizeFPropertyManager()
  2810. {
  2811. clear();
  2812. }
  2813. /*!
  2814. Returns the manager that creates the nested \e width and \e height
  2815. subproperties.
  2816. In order to provide editing widgets for the \e width and \e height
  2817. properties in a property browser widget, this manager must be
  2818. associated with an editor factory.
  2819. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  2820. */
  2821. QtDoublePropertyManager *QtSizeFPropertyManager::subDoublePropertyManager() const
  2822. {
  2823. return d_ptr->m_doublePropertyManager;
  2824. }
  2825. /*!
  2826. Returns the given \a property's value.
  2827. If the given \a property is not managed by this manager, this
  2828. function returns an invalid size
  2829. \sa setValue()
  2830. */
  2831. QSizeF QtSizeFPropertyManager::value(const QtProperty *property) const
  2832. {
  2833. return getValue<QSizeF>(d_ptr->m_values, property);
  2834. }
  2835. /*!
  2836. Returns the given \a property's precision, in decimals.
  2837. \sa setDecimals()
  2838. */
  2839. int QtSizeFPropertyManager::decimals(const QtProperty *property) const
  2840. {
  2841. return getData<int>(d_ptr->m_values, &QtSizeFPropertyManagerPrivate::Data::decimals, property, 0);
  2842. }
  2843. /*!
  2844. Returns the given \a property's minimum size value.
  2845. \sa setMinimum(), maximum(), setRange()
  2846. */
  2847. QSizeF QtSizeFPropertyManager::minimum(const QtProperty *property) const
  2848. {
  2849. return getMinimum<QSizeF>(d_ptr->m_values, property);
  2850. }
  2851. /*!
  2852. Returns the given \a property's maximum size value.
  2853. \sa setMaximum(), minimum(), setRange()
  2854. */
  2855. QSizeF QtSizeFPropertyManager::maximum(const QtProperty *property) const
  2856. {
  2857. return getMaximum<QSizeF>(d_ptr->m_values, property);
  2858. }
  2859. /*!
  2860. \reimp
  2861. */
  2862. QString QtSizeFPropertyManager::valueText(const QtProperty *property) const
  2863. {
  2864. const QtSizeFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  2865. if (it == d_ptr->m_values.constEnd())
  2866. return QString();
  2867. const QSizeF v = it.value().val;
  2868. const int dec = it.value().decimals;
  2869. return tr("%1 x %2").arg(QString::number(v.width(), 'f', dec))
  2870. .arg(QString::number(v.height(), 'f', dec));
  2871. }
  2872. /*!
  2873. \fn void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &value)
  2874. Sets the value of the given \a property to \a value.
  2875. If the specified \a value is not valid according to the given \a
  2876. property's size range, the \a value is adjusted to the nearest
  2877. valid value within the size range.
  2878. \sa value(), setRange(), valueChanged()
  2879. */
  2880. void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &val)
  2881. {
  2882. setValueInRange<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr.data(),
  2883. &QtSizeFPropertyManager::propertyChanged,
  2884. &QtSizeFPropertyManager::valueChanged,
  2885. property, val, &QtSizeFPropertyManagerPrivate::setValue);
  2886. }
  2887. /*!
  2888. \fn void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
  2889. Sets the precision of the given \a property to \a prec.
  2890. The valid decimal range is 0-13. The default is 2.
  2891. \sa decimals()
  2892. */
  2893. void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
  2894. {
  2895. const QtSizeFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  2896. if (it == d_ptr->m_values.end())
  2897. return;
  2898. QtSizeFPropertyManagerPrivate::Data data = it.value();
  2899. if (prec > 13)
  2900. prec = 13;
  2901. else if (prec < 0)
  2902. prec = 0;
  2903. if (data.decimals == prec)
  2904. return;
  2905. data.decimals = prec;
  2906. d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
  2907. d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
  2908. it.value() = data;
  2909. emit decimalsChanged(property, data.decimals);
  2910. }
  2911. /*!
  2912. Sets the minimum size value for the given \a property to \a minVal.
  2913. When setting the minimum size value, the maximum and current
  2914. values are adjusted if necessary (ensuring that the size range
  2915. remains valid and that the current value is within the range).
  2916. \sa minimum(), setRange(), rangeChanged()
  2917. */
  2918. void QtSizeFPropertyManager::setMinimum(QtProperty *property, const QSizeF &minVal)
  2919. {
  2920. setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr.data(),
  2921. &QtSizeFPropertyManager::propertyChanged,
  2922. &QtSizeFPropertyManager::valueChanged,
  2923. &QtSizeFPropertyManager::rangeChanged,
  2924. property,
  2925. &QtSizeFPropertyManagerPrivate::Data::minimumValue,
  2926. &QtSizeFPropertyManagerPrivate::Data::setMinimumValue,
  2927. minVal, &QtSizeFPropertyManagerPrivate::setRange);
  2928. }
  2929. /*!
  2930. Sets the maximum size value for the given \a property to \a maxVal.
  2931. When setting the maximum size value, the minimum and current
  2932. values are adjusted if necessary (ensuring that the size range
  2933. remains valid and that the current value is within the range).
  2934. \sa maximum(), setRange(), rangeChanged()
  2935. */
  2936. void QtSizeFPropertyManager::setMaximum(QtProperty *property, const QSizeF &maxVal)
  2937. {
  2938. setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr.data(),
  2939. &QtSizeFPropertyManager::propertyChanged,
  2940. &QtSizeFPropertyManager::valueChanged,
  2941. &QtSizeFPropertyManager::rangeChanged,
  2942. property,
  2943. &QtSizeFPropertyManagerPrivate::Data::maximumValue,
  2944. &QtSizeFPropertyManagerPrivate::Data::setMaximumValue,
  2945. maxVal, &QtSizeFPropertyManagerPrivate::setRange);
  2946. }
  2947. /*!
  2948. \fn void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
  2949. Sets the range of valid values.
  2950. This is a convenience function defining the range of valid values
  2951. in one go; setting the \a minimum and \a maximum values for the
  2952. given \a property with a single function call.
  2953. When setting a new range, the current value is adjusted if
  2954. necessary (ensuring that the value remains within the range).
  2955. \sa setMinimum(), setMaximum(), rangeChanged()
  2956. */
  2957. void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minVal, const QSizeF &maxVal)
  2958. {
  2959. setBorderValues<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr.data(),
  2960. &QtSizeFPropertyManager::propertyChanged,
  2961. &QtSizeFPropertyManager::valueChanged,
  2962. &QtSizeFPropertyManager::rangeChanged,
  2963. property, minVal, maxVal, &QtSizeFPropertyManagerPrivate::setRange);
  2964. }
  2965. /*!
  2966. \reimp
  2967. */
  2968. void QtSizeFPropertyManager::initializeProperty(QtProperty *property)
  2969. {
  2970. d_ptr->m_values[property] = QtSizeFPropertyManagerPrivate::Data();
  2971. QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
  2972. wProp->setPropertyName(tr("Width"));
  2973. d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
  2974. d_ptr->m_doublePropertyManager->setValue(wProp, 0);
  2975. d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
  2976. d_ptr->m_propertyToW[property] = wProp;
  2977. d_ptr->m_wToProperty[wProp] = property;
  2978. property->addSubProperty(wProp);
  2979. QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
  2980. hProp->setPropertyName(tr("Height"));
  2981. d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
  2982. d_ptr->m_doublePropertyManager->setValue(hProp, 0);
  2983. d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
  2984. d_ptr->m_propertyToH[property] = hProp;
  2985. d_ptr->m_hToProperty[hProp] = property;
  2986. property->addSubProperty(hProp);
  2987. }
  2988. /*!
  2989. \reimp
  2990. */
  2991. void QtSizeFPropertyManager::uninitializeProperty(QtProperty *property)
  2992. {
  2993. QtProperty *wProp = d_ptr->m_propertyToW[property];
  2994. if (wProp) {
  2995. d_ptr->m_wToProperty.remove(wProp);
  2996. delete wProp;
  2997. }
  2998. d_ptr->m_propertyToW.remove(property);
  2999. QtProperty *hProp = d_ptr->m_propertyToH[property];
  3000. if (hProp) {
  3001. d_ptr->m_hToProperty.remove(hProp);
  3002. delete hProp;
  3003. }
  3004. d_ptr->m_propertyToH.remove(property);
  3005. d_ptr->m_values.remove(property);
  3006. }
  3007. // QtRectPropertyManager
  3008. class QtRectPropertyManagerPrivate
  3009. {
  3010. QtRectPropertyManager *q_ptr;
  3011. Q_DECLARE_PUBLIC(QtRectPropertyManager)
  3012. public:
  3013. void slotIntChanged(QtProperty *property, int value);
  3014. void slotPropertyDestroyed(QtProperty *property);
  3015. void setConstraint(QtProperty *property, const QRect &constraint, const QRect &val);
  3016. struct Data
  3017. {
  3018. QRect val{0, 0, 0, 0};
  3019. QRect constraint;
  3020. };
  3021. typedef QMap<const QtProperty *, Data> PropertyValueMap;
  3022. PropertyValueMap m_values;
  3023. QtIntPropertyManager *m_intPropertyManager;
  3024. QMap<const QtProperty *, QtProperty *> m_propertyToX;
  3025. QMap<const QtProperty *, QtProperty *> m_propertyToY;
  3026. QMap<const QtProperty *, QtProperty *> m_propertyToW;
  3027. QMap<const QtProperty *, QtProperty *> m_propertyToH;
  3028. QMap<const QtProperty *, QtProperty *> m_xToProperty;
  3029. QMap<const QtProperty *, QtProperty *> m_yToProperty;
  3030. QMap<const QtProperty *, QtProperty *> m_wToProperty;
  3031. QMap<const QtProperty *, QtProperty *> m_hToProperty;
  3032. };
  3033. void QtRectPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
  3034. {
  3035. if (QtProperty *prop = m_xToProperty.value(property, 0)) {
  3036. QRect r = m_values[prop].val;
  3037. r.moveLeft(value);
  3038. q_ptr->setValue(prop, r);
  3039. } else if (QtProperty *prop = m_yToProperty.value(property)) {
  3040. QRect r = m_values[prop].val;
  3041. r.moveTop(value);
  3042. q_ptr->setValue(prop, r);
  3043. } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
  3044. Data data = m_values[prop];
  3045. QRect r = data.val;
  3046. r.setWidth(value);
  3047. if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
  3048. r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
  3049. }
  3050. q_ptr->setValue(prop, r);
  3051. } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
  3052. Data data = m_values[prop];
  3053. QRect r = data.val;
  3054. r.setHeight(value);
  3055. if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
  3056. r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
  3057. }
  3058. q_ptr->setValue(prop, r);
  3059. }
  3060. }
  3061. void QtRectPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
  3062. {
  3063. if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
  3064. m_propertyToX[pointProp] = 0;
  3065. m_xToProperty.remove(property);
  3066. } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
  3067. m_propertyToY[pointProp] = 0;
  3068. m_yToProperty.remove(property);
  3069. } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
  3070. m_propertyToW[pointProp] = 0;
  3071. m_wToProperty.remove(property);
  3072. } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
  3073. m_propertyToH[pointProp] = 0;
  3074. m_hToProperty.remove(property);
  3075. }
  3076. }
  3077. void QtRectPropertyManagerPrivate::setConstraint(QtProperty *property,
  3078. const QRect &constraint, const QRect &val)
  3079. {
  3080. const bool isNull = constraint.isNull();
  3081. const int left = isNull ? INT_MIN : constraint.left();
  3082. const int right = isNull ? INT_MAX : constraint.left() + constraint.width();
  3083. const int top = isNull ? INT_MIN : constraint.top();
  3084. const int bottom = isNull ? INT_MAX : constraint.top() + constraint.height();
  3085. const int width = isNull ? INT_MAX : constraint.width();
  3086. const int height = isNull ? INT_MAX : constraint.height();
  3087. m_intPropertyManager->setRange(m_propertyToX[property], left, right);
  3088. m_intPropertyManager->setRange(m_propertyToY[property], top, bottom);
  3089. m_intPropertyManager->setRange(m_propertyToW[property], 0, width);
  3090. m_intPropertyManager->setRange(m_propertyToH[property], 0, height);
  3091. m_intPropertyManager->setValue(m_propertyToX[property], val.x());
  3092. m_intPropertyManager->setValue(m_propertyToY[property], val.y());
  3093. m_intPropertyManager->setValue(m_propertyToW[property], val.width());
  3094. m_intPropertyManager->setValue(m_propertyToH[property], val.height());
  3095. }
  3096. /*!
  3097. \class QtRectPropertyManager
  3098. \internal
  3099. \inmodule QtDesigner
  3100. \since 4.4
  3101. \brief The QtRectPropertyManager provides and manages QRect properties.
  3102. A rectangle property has nested \e x, \e y, \e width and \e height
  3103. subproperties. The top-level property's value can be retrieved
  3104. using the value() function, and set using the setValue() slot.
  3105. The subproperties are created by a QtIntPropertyManager object. This
  3106. manager can be retrieved using the subIntPropertyManager() function. In
  3107. order to provide editing widgets for the subproperties in a
  3108. property browser widget, this manager must be associated with an
  3109. editor factory.
  3110. A rectangle property also has a constraint rectangle which can be
  3111. retrieved using the constraint() function, and set using the
  3112. setConstraint() slot.
  3113. In addition, QtRectPropertyManager provides the valueChanged() signal
  3114. which is emitted whenever a property created by this manager
  3115. changes, and the constraintChanged() signal which is emitted
  3116. whenever such a property changes its constraint rectangle.
  3117. \sa QtAbstractPropertyManager, QtIntPropertyManager, QtRectFPropertyManager
  3118. */
  3119. /*!
  3120. \fn void QtRectPropertyManager::valueChanged(QtProperty *property, const QRect &value)
  3121. This signal is emitted whenever a property created by this manager
  3122. changes its value, passing a pointer to the \a property and the new
  3123. \a value as parameters.
  3124. \sa setValue()
  3125. */
  3126. /*!
  3127. \fn void QtRectPropertyManager::constraintChanged(QtProperty *property, const QRect &constraint)
  3128. This signal is emitted whenever property changes its constraint
  3129. rectangle, passing a pointer to the \a property and the new \a
  3130. constraint rectangle as parameters.
  3131. \sa setConstraint()
  3132. */
  3133. /*!
  3134. Creates a manager with the given \a parent.
  3135. */
  3136. QtRectPropertyManager::QtRectPropertyManager(QObject *parent)
  3137. : QtAbstractPropertyManager(parent), d_ptr(new QtRectPropertyManagerPrivate)
  3138. {
  3139. d_ptr->q_ptr = this;
  3140. d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
  3141. connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  3142. this, SLOT(slotIntChanged(QtProperty*,int)));
  3143. connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  3144. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  3145. }
  3146. /*!
  3147. Destroys this manager, and all the properties it has created.
  3148. */
  3149. QtRectPropertyManager::~QtRectPropertyManager()
  3150. {
  3151. clear();
  3152. }
  3153. /*!
  3154. Returns the manager that creates the nested \e x, \e y, \e width
  3155. and \e height subproperties.
  3156. In order to provide editing widgets for the mentioned
  3157. subproperties in a property browser widget, this manager must be
  3158. associated with an editor factory.
  3159. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  3160. */
  3161. QtIntPropertyManager *QtRectPropertyManager::subIntPropertyManager() const
  3162. {
  3163. return d_ptr->m_intPropertyManager;
  3164. }
  3165. /*!
  3166. Returns the given \a property's value.
  3167. If the given \a property is not managed by this manager, this
  3168. function returns an invalid rectangle.
  3169. \sa setValue(), constraint()
  3170. */
  3171. QRect QtRectPropertyManager::value(const QtProperty *property) const
  3172. {
  3173. return getValue<QRect>(d_ptr->m_values, property);
  3174. }
  3175. /*!
  3176. Returns the given \a property's constraining rectangle. If returned value is null QRect it means there is no constraint applied.
  3177. \sa value(), setConstraint()
  3178. */
  3179. QRect QtRectPropertyManager::constraint(const QtProperty *property) const
  3180. {
  3181. return getData<QRect>(d_ptr->m_values, &QtRectPropertyManagerPrivate::Data::constraint, property, QRect());
  3182. }
  3183. /*!
  3184. \reimp
  3185. */
  3186. QString QtRectPropertyManager::valueText(const QtProperty *property) const
  3187. {
  3188. const QtRectPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  3189. if (it == d_ptr->m_values.constEnd())
  3190. return QString();
  3191. const QRect v = it.value().val;
  3192. return tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x()))
  3193. .arg(QString::number(v.y()))
  3194. .arg(QString::number(v.width()))
  3195. .arg(QString::number(v.height()));
  3196. }
  3197. /*!
  3198. \fn void QtRectPropertyManager::setValue(QtProperty *property, const QRect &value)
  3199. Sets the value of the given \a property to \a value. Nested
  3200. properties are updated automatically.
  3201. If the specified \a value is not inside the given \a property's
  3202. constraining rectangle, the value is adjusted accordingly to fit
  3203. within the constraint.
  3204. \sa value(), setConstraint(), valueChanged()
  3205. */
  3206. void QtRectPropertyManager::setValue(QtProperty *property, const QRect &val)
  3207. {
  3208. const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  3209. if (it == d_ptr->m_values.end())
  3210. return;
  3211. QtRectPropertyManagerPrivate::Data data = it.value();
  3212. QRect newRect = val.normalized();
  3213. if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
  3214. const QRect r1 = data.constraint;
  3215. const QRect r2 = newRect;
  3216. newRect.setLeft(qMax(r1.left(), r2.left()));
  3217. newRect.setRight(qMin(r1.right(), r2.right()));
  3218. newRect.setTop(qMax(r1.top(), r2.top()));
  3219. newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
  3220. if (newRect.width() < 0 || newRect.height() < 0)
  3221. return;
  3222. }
  3223. if (data.val == newRect)
  3224. return;
  3225. data.val = newRect;
  3226. it.value() = data;
  3227. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
  3228. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
  3229. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
  3230. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
  3231. emit propertyChanged(property);
  3232. emit valueChanged(property, data.val);
  3233. }
  3234. /*!
  3235. Sets the given \a property's constraining rectangle to \a
  3236. constraint.
  3237. When setting the constraint, the current value is adjusted if
  3238. necessary (ensuring that the current rectangle value is inside the
  3239. constraint). In order to reset the constraint pass a null QRect value.
  3240. \sa setValue(), constraint(), constraintChanged()
  3241. */
  3242. void QtRectPropertyManager::setConstraint(QtProperty *property, const QRect &constraint)
  3243. {
  3244. const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  3245. if (it == d_ptr->m_values.end())
  3246. return;
  3247. QtRectPropertyManagerPrivate::Data data = it.value();
  3248. QRect newConstraint = constraint.normalized();
  3249. if (data.constraint == newConstraint)
  3250. return;
  3251. const QRect oldVal = data.val;
  3252. data.constraint = newConstraint;
  3253. if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
  3254. QRect r1 = data.constraint;
  3255. QRect r2 = data.val;
  3256. if (r2.width() > r1.width())
  3257. r2.setWidth(r1.width());
  3258. if (r2.height() > r1.height())
  3259. r2.setHeight(r1.height());
  3260. if (r2.left() < r1.left())
  3261. r2.moveLeft(r1.left());
  3262. else if (r2.right() > r1.right())
  3263. r2.moveRight(r1.right());
  3264. if (r2.top() < r1.top())
  3265. r2.moveTop(r1.top());
  3266. else if (r2.bottom() > r1.bottom())
  3267. r2.moveBottom(r1.bottom());
  3268. data.val = r2;
  3269. }
  3270. it.value() = data;
  3271. emit constraintChanged(property, data.constraint);
  3272. d_ptr->setConstraint(property, data.constraint, data.val);
  3273. if (data.val == oldVal)
  3274. return;
  3275. emit propertyChanged(property);
  3276. emit valueChanged(property, data.val);
  3277. }
  3278. /*!
  3279. \reimp
  3280. */
  3281. void QtRectPropertyManager::initializeProperty(QtProperty *property)
  3282. {
  3283. d_ptr->m_values[property] = QtRectPropertyManagerPrivate::Data();
  3284. QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
  3285. xProp->setPropertyName(tr("X"));
  3286. d_ptr->m_intPropertyManager->setValue(xProp, 0);
  3287. d_ptr->m_propertyToX[property] = xProp;
  3288. d_ptr->m_xToProperty[xProp] = property;
  3289. property->addSubProperty(xProp);
  3290. QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
  3291. yProp->setPropertyName(tr("Y"));
  3292. d_ptr->m_intPropertyManager->setValue(yProp, 0);
  3293. d_ptr->m_propertyToY[property] = yProp;
  3294. d_ptr->m_yToProperty[yProp] = property;
  3295. property->addSubProperty(yProp);
  3296. QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
  3297. wProp->setPropertyName(tr("Width"));
  3298. d_ptr->m_intPropertyManager->setValue(wProp, 0);
  3299. d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
  3300. d_ptr->m_propertyToW[property] = wProp;
  3301. d_ptr->m_wToProperty[wProp] = property;
  3302. property->addSubProperty(wProp);
  3303. QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
  3304. hProp->setPropertyName(tr("Height"));
  3305. d_ptr->m_intPropertyManager->setValue(hProp, 0);
  3306. d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
  3307. d_ptr->m_propertyToH[property] = hProp;
  3308. d_ptr->m_hToProperty[hProp] = property;
  3309. property->addSubProperty(hProp);
  3310. }
  3311. /*!
  3312. \reimp
  3313. */
  3314. void QtRectPropertyManager::uninitializeProperty(QtProperty *property)
  3315. {
  3316. QtProperty *xProp = d_ptr->m_propertyToX[property];
  3317. if (xProp) {
  3318. d_ptr->m_xToProperty.remove(xProp);
  3319. delete xProp;
  3320. }
  3321. d_ptr->m_propertyToX.remove(property);
  3322. QtProperty *yProp = d_ptr->m_propertyToY[property];
  3323. if (yProp) {
  3324. d_ptr->m_yToProperty.remove(yProp);
  3325. delete yProp;
  3326. }
  3327. d_ptr->m_propertyToY.remove(property);
  3328. QtProperty *wProp = d_ptr->m_propertyToW[property];
  3329. if (wProp) {
  3330. d_ptr->m_wToProperty.remove(wProp);
  3331. delete wProp;
  3332. }
  3333. d_ptr->m_propertyToW.remove(property);
  3334. QtProperty *hProp = d_ptr->m_propertyToH[property];
  3335. if (hProp) {
  3336. d_ptr->m_hToProperty.remove(hProp);
  3337. delete hProp;
  3338. }
  3339. d_ptr->m_propertyToH.remove(property);
  3340. d_ptr->m_values.remove(property);
  3341. }
  3342. // QtRectFPropertyManager
  3343. class QtRectFPropertyManagerPrivate
  3344. {
  3345. QtRectFPropertyManager *q_ptr;
  3346. Q_DECLARE_PUBLIC(QtRectFPropertyManager)
  3347. public:
  3348. void slotDoubleChanged(QtProperty *property, double value);
  3349. void slotPropertyDestroyed(QtProperty *property);
  3350. void setConstraint(QtProperty *property, const QRectF &constraint, const QRectF &val);
  3351. struct Data
  3352. {
  3353. QRectF val{0, 0, 0, 0};
  3354. QRectF constraint;
  3355. int decimals{2};
  3356. };
  3357. typedef QMap<const QtProperty *, Data> PropertyValueMap;
  3358. PropertyValueMap m_values;
  3359. QtDoublePropertyManager *m_doublePropertyManager;
  3360. QMap<const QtProperty *, QtProperty *> m_propertyToX;
  3361. QMap<const QtProperty *, QtProperty *> m_propertyToY;
  3362. QMap<const QtProperty *, QtProperty *> m_propertyToW;
  3363. QMap<const QtProperty *, QtProperty *> m_propertyToH;
  3364. QMap<const QtProperty *, QtProperty *> m_xToProperty;
  3365. QMap<const QtProperty *, QtProperty *> m_yToProperty;
  3366. QMap<const QtProperty *, QtProperty *> m_wToProperty;
  3367. QMap<const QtProperty *, QtProperty *> m_hToProperty;
  3368. };
  3369. void QtRectFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
  3370. {
  3371. if (QtProperty *prop = m_xToProperty.value(property, 0)) {
  3372. QRectF r = m_values[prop].val;
  3373. r.moveLeft(value);
  3374. q_ptr->setValue(prop, r);
  3375. } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
  3376. QRectF r = m_values[prop].val;
  3377. r.moveTop(value);
  3378. q_ptr->setValue(prop, r);
  3379. } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
  3380. Data data = m_values[prop];
  3381. QRectF r = data.val;
  3382. r.setWidth(value);
  3383. if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
  3384. r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
  3385. }
  3386. q_ptr->setValue(prop, r);
  3387. } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
  3388. Data data = m_values[prop];
  3389. QRectF r = data.val;
  3390. r.setHeight(value);
  3391. if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
  3392. r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
  3393. }
  3394. q_ptr->setValue(prop, r);
  3395. }
  3396. }
  3397. void QtRectFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
  3398. {
  3399. if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
  3400. m_propertyToX[pointProp] = 0;
  3401. m_xToProperty.remove(property);
  3402. } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
  3403. m_propertyToY[pointProp] = 0;
  3404. m_yToProperty.remove(property);
  3405. } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
  3406. m_propertyToW[pointProp] = 0;
  3407. m_wToProperty.remove(property);
  3408. } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
  3409. m_propertyToH[pointProp] = 0;
  3410. m_hToProperty.remove(property);
  3411. }
  3412. }
  3413. void QtRectFPropertyManagerPrivate::setConstraint(QtProperty *property,
  3414. const QRectF &constraint, const QRectF &val)
  3415. {
  3416. const bool isNull = constraint.isNull();
  3417. const float left = isNull ? FLT_MIN : constraint.left();
  3418. const float right = isNull ? FLT_MAX : constraint.left() + constraint.width();
  3419. const float top = isNull ? FLT_MIN : constraint.top();
  3420. const float bottom = isNull ? FLT_MAX : constraint.top() + constraint.height();
  3421. const float width = isNull ? FLT_MAX : constraint.width();
  3422. const float height = isNull ? FLT_MAX : constraint.height();
  3423. m_doublePropertyManager->setRange(m_propertyToX[property], left, right);
  3424. m_doublePropertyManager->setRange(m_propertyToY[property], top, bottom);
  3425. m_doublePropertyManager->setRange(m_propertyToW[property], 0, width);
  3426. m_doublePropertyManager->setRange(m_propertyToH[property], 0, height);
  3427. m_doublePropertyManager->setValue(m_propertyToX[property], val.x());
  3428. m_doublePropertyManager->setValue(m_propertyToY[property], val.y());
  3429. m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
  3430. m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
  3431. }
  3432. /*!
  3433. \class QtRectFPropertyManager
  3434. \internal
  3435. \inmodule QtDesigner
  3436. \since 4.4
  3437. \brief The QtRectFPropertyManager provides and manages QRectF properties.
  3438. A rectangle property has nested \e x, \e y, \e width and \e height
  3439. subproperties. The top-level property's value can be retrieved
  3440. using the value() function, and set using the setValue() slot.
  3441. The subproperties are created by a QtDoublePropertyManager object. This
  3442. manager can be retrieved using the subDoublePropertyManager() function. In
  3443. order to provide editing widgets for the subproperties in a
  3444. property browser widget, this manager must be associated with an
  3445. editor factory.
  3446. A rectangle property also has a constraint rectangle which can be
  3447. retrieved using the constraint() function, and set using the
  3448. setConstraint() slot.
  3449. In addition, QtRectFPropertyManager provides the valueChanged() signal
  3450. which is emitted whenever a property created by this manager
  3451. changes, and the constraintChanged() signal which is emitted
  3452. whenever such a property changes its constraint rectangle.
  3453. \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtRectPropertyManager
  3454. */
  3455. /*!
  3456. \fn void QtRectFPropertyManager::valueChanged(QtProperty *property, const QRectF &value)
  3457. This signal is emitted whenever a property created by this manager
  3458. changes its value, passing a pointer to the \a property and the new
  3459. \a value as parameters.
  3460. \sa setValue()
  3461. */
  3462. /*!
  3463. \fn void QtRectFPropertyManager::constraintChanged(QtProperty *property, const QRectF &constraint)
  3464. This signal is emitted whenever property changes its constraint
  3465. rectangle, passing a pointer to the \a property and the new \a
  3466. constraint rectangle as parameters.
  3467. \sa setConstraint()
  3468. */
  3469. /*!
  3470. \fn void QtRectFPropertyManager::decimalsChanged(QtProperty *property, int prec)
  3471. This signal is emitted whenever a property created by this manager
  3472. changes its precision of value, passing a pointer to the
  3473. \a property and the new \a prec value
  3474. \sa setDecimals()
  3475. */
  3476. /*!
  3477. Creates a manager with the given \a parent.
  3478. */
  3479. QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent)
  3480. : QtAbstractPropertyManager(parent), d_ptr(new QtRectFPropertyManagerPrivate)
  3481. {
  3482. d_ptr->q_ptr = this;
  3483. d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
  3484. connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
  3485. this, SLOT(slotDoubleChanged(QtProperty*,double)));
  3486. connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  3487. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  3488. }
  3489. /*!
  3490. Destroys this manager, and all the properties it has created.
  3491. */
  3492. QtRectFPropertyManager::~QtRectFPropertyManager()
  3493. {
  3494. clear();
  3495. }
  3496. /*!
  3497. Returns the manager that creates the nested \e x, \e y, \e width
  3498. and \e height subproperties.
  3499. In order to provide editing widgets for the mentioned
  3500. subproperties in a property browser widget, this manager must be
  3501. associated with an editor factory.
  3502. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  3503. */
  3504. QtDoublePropertyManager *QtRectFPropertyManager::subDoublePropertyManager() const
  3505. {
  3506. return d_ptr->m_doublePropertyManager;
  3507. }
  3508. /*!
  3509. Returns the given \a property's value.
  3510. If the given \a property is not managed by this manager, this
  3511. function returns an invalid rectangle.
  3512. \sa setValue(), constraint()
  3513. */
  3514. QRectF QtRectFPropertyManager::value(const QtProperty *property) const
  3515. {
  3516. return getValue<QRectF>(d_ptr->m_values, property);
  3517. }
  3518. /*!
  3519. Returns the given \a property's precision, in decimals.
  3520. \sa setDecimals()
  3521. */
  3522. int QtRectFPropertyManager::decimals(const QtProperty *property) const
  3523. {
  3524. return getData<int>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::decimals, property, 0);
  3525. }
  3526. /*!
  3527. Returns the given \a property's constraining rectangle. If returned value is null QRectF it means there is no constraint applied.
  3528. \sa value(), setConstraint()
  3529. */
  3530. QRectF QtRectFPropertyManager::constraint(const QtProperty *property) const
  3531. {
  3532. return getData<QRectF>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::constraint, property, QRect());
  3533. }
  3534. /*!
  3535. \reimp
  3536. */
  3537. QString QtRectFPropertyManager::valueText(const QtProperty *property) const
  3538. {
  3539. const QtRectFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  3540. if (it == d_ptr->m_values.constEnd())
  3541. return QString();
  3542. const QRectF v = it.value().val;
  3543. const int dec = it.value().decimals;
  3544. return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x(), 'f', dec))
  3545. .arg(QString::number(v.y(), 'f', dec))
  3546. .arg(QString::number(v.width(), 'f', dec))
  3547. .arg(QString::number(v.height(), 'f', dec)));
  3548. }
  3549. /*!
  3550. \fn void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &value)
  3551. Sets the value of the given \a property to \a value. Nested
  3552. properties are updated automatically.
  3553. If the specified \a value is not inside the given \a property's
  3554. constraining rectangle, the value is adjusted accordingly to fit
  3555. within the constraint.
  3556. \sa value(), setConstraint(), valueChanged()
  3557. */
  3558. void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &val)
  3559. {
  3560. const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  3561. if (it == d_ptr->m_values.end())
  3562. return;
  3563. QtRectFPropertyManagerPrivate::Data data = it.value();
  3564. QRectF newRect = val.normalized();
  3565. if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
  3566. const QRectF r1 = data.constraint;
  3567. const QRectF r2 = newRect;
  3568. newRect.setLeft(qMax(r1.left(), r2.left()));
  3569. newRect.setRight(qMin(r1.right(), r2.right()));
  3570. newRect.setTop(qMax(r1.top(), r2.top()));
  3571. newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
  3572. if (newRect.width() < 0 || newRect.height() < 0)
  3573. return;
  3574. }
  3575. if (data.val == newRect)
  3576. return;
  3577. data.val = newRect;
  3578. it.value() = data;
  3579. d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
  3580. d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
  3581. d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
  3582. d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
  3583. emit propertyChanged(property);
  3584. emit valueChanged(property, data.val);
  3585. }
  3586. /*!
  3587. Sets the given \a property's constraining rectangle to \a
  3588. constraint.
  3589. When setting the constraint, the current value is adjusted if
  3590. necessary (ensuring that the current rectangle value is inside the
  3591. constraint). In order to reset the constraint pass a null QRectF value.
  3592. \sa setValue(), constraint(), constraintChanged()
  3593. */
  3594. void QtRectFPropertyManager::setConstraint(QtProperty *property, const QRectF &constraint)
  3595. {
  3596. const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  3597. if (it == d_ptr->m_values.end())
  3598. return;
  3599. QtRectFPropertyManagerPrivate::Data data = it.value();
  3600. QRectF newConstraint = constraint.normalized();
  3601. if (data.constraint == newConstraint)
  3602. return;
  3603. const QRectF oldVal = data.val;
  3604. data.constraint = newConstraint;
  3605. if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
  3606. QRectF r1 = data.constraint;
  3607. QRectF r2 = data.val;
  3608. if (r2.width() > r1.width())
  3609. r2.setWidth(r1.width());
  3610. if (r2.height() > r1.height())
  3611. r2.setHeight(r1.height());
  3612. if (r2.left() < r1.left())
  3613. r2.moveLeft(r1.left());
  3614. else if (r2.right() > r1.right())
  3615. r2.moveRight(r1.right());
  3616. if (r2.top() < r1.top())
  3617. r2.moveTop(r1.top());
  3618. else if (r2.bottom() > r1.bottom())
  3619. r2.moveBottom(r1.bottom());
  3620. data.val = r2;
  3621. }
  3622. it.value() = data;
  3623. emit constraintChanged(property, data.constraint);
  3624. d_ptr->setConstraint(property, data.constraint, data.val);
  3625. if (data.val == oldVal)
  3626. return;
  3627. emit propertyChanged(property);
  3628. emit valueChanged(property, data.val);
  3629. }
  3630. /*!
  3631. \fn void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
  3632. Sets the precision of the given \a property to \a prec.
  3633. The valid decimal range is 0-13. The default is 2.
  3634. \sa decimals()
  3635. */
  3636. void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
  3637. {
  3638. const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  3639. if (it == d_ptr->m_values.end())
  3640. return;
  3641. QtRectFPropertyManagerPrivate::Data data = it.value();
  3642. if (prec > 13)
  3643. prec = 13;
  3644. else if (prec < 0)
  3645. prec = 0;
  3646. if (data.decimals == prec)
  3647. return;
  3648. data.decimals = prec;
  3649. d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
  3650. d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
  3651. d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
  3652. d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
  3653. it.value() = data;
  3654. emit decimalsChanged(property, data.decimals);
  3655. }
  3656. /*!
  3657. \reimp
  3658. */
  3659. void QtRectFPropertyManager::initializeProperty(QtProperty *property)
  3660. {
  3661. d_ptr->m_values[property] = QtRectFPropertyManagerPrivate::Data();
  3662. QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
  3663. xProp->setPropertyName(tr("X"));
  3664. d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
  3665. d_ptr->m_doublePropertyManager->setValue(xProp, 0);
  3666. d_ptr->m_propertyToX[property] = xProp;
  3667. d_ptr->m_xToProperty[xProp] = property;
  3668. property->addSubProperty(xProp);
  3669. QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
  3670. yProp->setPropertyName(tr("Y"));
  3671. d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
  3672. d_ptr->m_doublePropertyManager->setValue(yProp, 0);
  3673. d_ptr->m_propertyToY[property] = yProp;
  3674. d_ptr->m_yToProperty[yProp] = property;
  3675. property->addSubProperty(yProp);
  3676. QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
  3677. wProp->setPropertyName(tr("Width"));
  3678. d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
  3679. d_ptr->m_doublePropertyManager->setValue(wProp, 0);
  3680. d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
  3681. d_ptr->m_propertyToW[property] = wProp;
  3682. d_ptr->m_wToProperty[wProp] = property;
  3683. property->addSubProperty(wProp);
  3684. QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
  3685. hProp->setPropertyName(tr("Height"));
  3686. d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
  3687. d_ptr->m_doublePropertyManager->setValue(hProp, 0);
  3688. d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
  3689. d_ptr->m_propertyToH[property] = hProp;
  3690. d_ptr->m_hToProperty[hProp] = property;
  3691. property->addSubProperty(hProp);
  3692. }
  3693. /*!
  3694. \reimp
  3695. */
  3696. void QtRectFPropertyManager::uninitializeProperty(QtProperty *property)
  3697. {
  3698. QtProperty *xProp = d_ptr->m_propertyToX[property];
  3699. if (xProp) {
  3700. d_ptr->m_xToProperty.remove(xProp);
  3701. delete xProp;
  3702. }
  3703. d_ptr->m_propertyToX.remove(property);
  3704. QtProperty *yProp = d_ptr->m_propertyToY[property];
  3705. if (yProp) {
  3706. d_ptr->m_yToProperty.remove(yProp);
  3707. delete yProp;
  3708. }
  3709. d_ptr->m_propertyToY.remove(property);
  3710. QtProperty *wProp = d_ptr->m_propertyToW[property];
  3711. if (wProp) {
  3712. d_ptr->m_wToProperty.remove(wProp);
  3713. delete wProp;
  3714. }
  3715. d_ptr->m_propertyToW.remove(property);
  3716. QtProperty *hProp = d_ptr->m_propertyToH[property];
  3717. if (hProp) {
  3718. d_ptr->m_hToProperty.remove(hProp);
  3719. delete hProp;
  3720. }
  3721. d_ptr->m_propertyToH.remove(property);
  3722. d_ptr->m_values.remove(property);
  3723. }
  3724. // QtEnumPropertyManager
  3725. class QtEnumPropertyManagerPrivate
  3726. {
  3727. QtEnumPropertyManager *q_ptr;
  3728. Q_DECLARE_PUBLIC(QtEnumPropertyManager)
  3729. public:
  3730. struct Data
  3731. {
  3732. int val{-1};
  3733. QStringList enumNames;
  3734. QMap<int, QIcon> enumIcons;
  3735. };
  3736. typedef QMap<const QtProperty *, Data> PropertyValueMap;
  3737. PropertyValueMap m_values;
  3738. };
  3739. /*!
  3740. \class QtEnumPropertyManager
  3741. \internal
  3742. \inmodule QtDesigner
  3743. \since 4.4
  3744. \brief The QtEnumPropertyManager provides and manages enum properties.
  3745. Each enum property has an associated list of enum names which can
  3746. be retrieved using the enumNames() function, and set using the
  3747. corresponding setEnumNames() function. An enum property's value is
  3748. represented by an index in this list, and can be retrieved and set
  3749. using the value() and setValue() slots respectively.
  3750. Each enum value can also have an associated icon. The mapping from
  3751. values to icons can be set using the setEnumIcons() function and
  3752. queried with the enumIcons() function.
  3753. In addition, QtEnumPropertyManager provides the valueChanged() signal
  3754. which is emitted whenever a property created by this manager
  3755. changes. The enumNamesChanged() or enumIconsChanged() signal is emitted
  3756. whenever the list of enum names or icons is altered.
  3757. \sa QtAbstractPropertyManager, QtEnumEditorFactory
  3758. */
  3759. /*!
  3760. \fn void QtEnumPropertyManager::valueChanged(QtProperty *property, int value)
  3761. This signal is emitted whenever a property created by this manager
  3762. changes its value, passing a pointer to the \a property and the new
  3763. \a value as parameters.
  3764. \sa setValue()
  3765. */
  3766. /*!
  3767. \fn void QtEnumPropertyManager::enumNamesChanged(QtProperty *property, const QStringList &names)
  3768. This signal is emitted whenever a property created by this manager
  3769. changes its enum names, passing a pointer to the \a property and
  3770. the new \a names as parameters.
  3771. \sa setEnumNames()
  3772. */
  3773. /*!
  3774. \fn void QtEnumPropertyManager::enumIconsChanged(QtProperty *property, const QMap<int, QIcon> &icons)
  3775. This signal is emitted whenever a property created by this manager
  3776. changes its enum icons, passing a pointer to the \a property and
  3777. the new mapping of values to \a icons as parameters.
  3778. \sa setEnumIcons()
  3779. */
  3780. /*!
  3781. Creates a manager with the given \a parent.
  3782. */
  3783. QtEnumPropertyManager::QtEnumPropertyManager(QObject *parent)
  3784. : QtAbstractPropertyManager(parent), d_ptr(new QtEnumPropertyManagerPrivate)
  3785. {
  3786. d_ptr->q_ptr = this;
  3787. }
  3788. /*!
  3789. Destroys this manager, and all the properties it has created.
  3790. */
  3791. QtEnumPropertyManager::~QtEnumPropertyManager()
  3792. {
  3793. clear();
  3794. }
  3795. /*!
  3796. Returns the given \a property's value which is an index in the
  3797. list returned by enumNames()
  3798. If the given property is not managed by this manager, this
  3799. function returns -1.
  3800. \sa enumNames(), setValue()
  3801. */
  3802. int QtEnumPropertyManager::value(const QtProperty *property) const
  3803. {
  3804. return getValue<int>(d_ptr->m_values, property, -1);
  3805. }
  3806. /*!
  3807. Returns the given \a property's list of enum names.
  3808. \sa value(), setEnumNames()
  3809. */
  3810. QStringList QtEnumPropertyManager::enumNames(const QtProperty *property) const
  3811. {
  3812. return getData<QStringList>(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumNames, property, QStringList());
  3813. }
  3814. /*!
  3815. Returns the given \a property's map of enum values to their icons.
  3816. \sa value(), setEnumIcons()
  3817. */
  3818. QMap<int, QIcon> QtEnumPropertyManager::enumIcons(const QtProperty *property) const
  3819. {
  3820. return getData<QMap<int, QIcon> >(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumIcons, property, QMap<int, QIcon>());
  3821. }
  3822. /*!
  3823. \reimp
  3824. */
  3825. QString QtEnumPropertyManager::valueText(const QtProperty *property) const
  3826. {
  3827. const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  3828. if (it == d_ptr->m_values.constEnd())
  3829. return QString();
  3830. const QtEnumPropertyManagerPrivate::Data &data = it.value();
  3831. const int v = data.val;
  3832. if (v >= 0 && v < data.enumNames.count())
  3833. return data.enumNames.at(v);
  3834. return QString();
  3835. }
  3836. /*!
  3837. \reimp
  3838. */
  3839. QIcon QtEnumPropertyManager::valueIcon(const QtProperty *property) const
  3840. {
  3841. const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  3842. if (it == d_ptr->m_values.constEnd())
  3843. return QIcon();
  3844. const QtEnumPropertyManagerPrivate::Data &data = it.value();
  3845. const int v = data.val;
  3846. return data.enumIcons.value(v);
  3847. }
  3848. /*!
  3849. \fn void QtEnumPropertyManager::setValue(QtProperty *property, int value)
  3850. Sets the value of the given \a property to \a value.
  3851. The specified \a value must be less than the size of the given \a
  3852. property's enumNames() list, and larger than (or equal to) 0.
  3853. \sa value(), valueChanged()
  3854. */
  3855. void QtEnumPropertyManager::setValue(QtProperty *property, int val)
  3856. {
  3857. const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  3858. if (it == d_ptr->m_values.end())
  3859. return;
  3860. QtEnumPropertyManagerPrivate::Data data = it.value();
  3861. if (val >= data.enumNames.count())
  3862. return;
  3863. if (val < 0 && data.enumNames.count() > 0)
  3864. return;
  3865. if (val < 0)
  3866. val = -1;
  3867. if (data.val == val)
  3868. return;
  3869. data.val = val;
  3870. it.value() = data;
  3871. emit propertyChanged(property);
  3872. emit valueChanged(property, data.val);
  3873. }
  3874. /*!
  3875. Sets the given \a property's list of enum names to \a
  3876. enumNames. The \a property's current value is reset to 0
  3877. indicating the first item of the list.
  3878. If the specified \a enumNames list is empty, the \a property's
  3879. current value is set to -1.
  3880. \sa enumNames(), enumNamesChanged()
  3881. */
  3882. void QtEnumPropertyManager::setEnumNames(QtProperty *property, const QStringList &enumNames)
  3883. {
  3884. const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  3885. if (it == d_ptr->m_values.end())
  3886. return;
  3887. QtEnumPropertyManagerPrivate::Data data = it.value();
  3888. if (data.enumNames == enumNames)
  3889. return;
  3890. data.enumNames = enumNames;
  3891. data.val = -1;
  3892. if (enumNames.count() > 0)
  3893. data.val = 0;
  3894. it.value() = data;
  3895. emit enumNamesChanged(property, data.enumNames);
  3896. emit propertyChanged(property);
  3897. emit valueChanged(property, data.val);
  3898. }
  3899. /*!
  3900. Sets the given \a property's map of enum values to their icons to \a
  3901. enumIcons.
  3902. Each enum value can have associated icon. This association is represented with passed \a enumIcons map.
  3903. \sa enumNames(), enumNamesChanged()
  3904. */
  3905. void QtEnumPropertyManager::setEnumIcons(QtProperty *property, const QMap<int, QIcon> &enumIcons)
  3906. {
  3907. const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  3908. if (it == d_ptr->m_values.end())
  3909. return;
  3910. it.value().enumIcons = enumIcons;
  3911. emit enumIconsChanged(property, it.value().enumIcons);
  3912. emit propertyChanged(property);
  3913. }
  3914. /*!
  3915. \reimp
  3916. */
  3917. void QtEnumPropertyManager::initializeProperty(QtProperty *property)
  3918. {
  3919. d_ptr->m_values[property] = QtEnumPropertyManagerPrivate::Data();
  3920. }
  3921. /*!
  3922. \reimp
  3923. */
  3924. void QtEnumPropertyManager::uninitializeProperty(QtProperty *property)
  3925. {
  3926. d_ptr->m_values.remove(property);
  3927. }
  3928. // QtFlagPropertyManager
  3929. class QtFlagPropertyManagerPrivate
  3930. {
  3931. QtFlagPropertyManager *q_ptr;
  3932. Q_DECLARE_PUBLIC(QtFlagPropertyManager)
  3933. public:
  3934. void slotBoolChanged(QtProperty *property, bool value);
  3935. void slotPropertyDestroyed(QtProperty *property);
  3936. struct Data
  3937. {
  3938. int val{-1};
  3939. QStringList flagNames;
  3940. };
  3941. typedef QMap<const QtProperty *, Data> PropertyValueMap;
  3942. PropertyValueMap m_values;
  3943. QtBoolPropertyManager *m_boolPropertyManager;
  3944. QMap<const QtProperty *, QList<QtProperty *> > m_propertyToFlags;
  3945. QMap<const QtProperty *, QtProperty *> m_flagToProperty;
  3946. };
  3947. void QtFlagPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
  3948. {
  3949. QtProperty *prop = m_flagToProperty.value(property, 0);
  3950. if (prop == 0)
  3951. return;
  3952. const auto pfit = m_propertyToFlags.constFind(prop);
  3953. if (pfit == m_propertyToFlags.constEnd())
  3954. return;
  3955. int level = 0;
  3956. for (QtProperty *p : pfit.value()) {
  3957. if (p == property) {
  3958. int v = m_values[prop].val;
  3959. if (value) {
  3960. v |= (1 << level);
  3961. } else {
  3962. v &= ~(1 << level);
  3963. }
  3964. q_ptr->setValue(prop, v);
  3965. return;
  3966. }
  3967. level++;
  3968. }
  3969. }
  3970. void QtFlagPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
  3971. {
  3972. QtProperty *flagProperty = m_flagToProperty.value(property, 0);
  3973. if (flagProperty == 0)
  3974. return;
  3975. m_propertyToFlags[flagProperty].replace(m_propertyToFlags[flagProperty].indexOf(property), 0);
  3976. m_flagToProperty.remove(property);
  3977. }
  3978. /*!
  3979. \class QtFlagPropertyManager
  3980. \internal
  3981. \inmodule QtDesigner
  3982. \since 4.4
  3983. \brief The QtFlagPropertyManager provides and manages flag properties.
  3984. Each flag property has an associated list of flag names which can
  3985. be retrieved using the flagNames() function, and set using the
  3986. corresponding setFlagNames() function.
  3987. The flag manager provides properties with nested boolean
  3988. subproperties representing each flag, i.e. a flag property's value
  3989. is the binary combination of the subproperties' values. A
  3990. property's value can be retrieved and set using the value() and
  3991. setValue() slots respectively. The combination of flags is represented
  3992. by single int value - that's why it's possible to store up to
  3993. 32 independent flags in one flag property.
  3994. The subproperties are created by a QtBoolPropertyManager object. This
  3995. manager can be retrieved using the subBoolPropertyManager() function. In
  3996. order to provide editing widgets for the subproperties in a
  3997. property browser widget, this manager must be associated with an
  3998. editor factory.
  3999. In addition, QtFlagPropertyManager provides the valueChanged() signal
  4000. which is emitted whenever a property created by this manager
  4001. changes, and the flagNamesChanged() signal which is emitted
  4002. whenever the list of flag names is altered.
  4003. \sa QtAbstractPropertyManager, QtBoolPropertyManager
  4004. */
  4005. /*!
  4006. \fn void QtFlagPropertyManager::valueChanged(QtProperty *property, int value)
  4007. This signal is emitted whenever a property created by this manager
  4008. changes its value, passing a pointer to the \a property and the new
  4009. \a value as parameters.
  4010. \sa setValue()
  4011. */
  4012. /*!
  4013. \fn void QtFlagPropertyManager::flagNamesChanged(QtProperty *property, const QStringList &names)
  4014. This signal is emitted whenever a property created by this manager
  4015. changes its flag names, passing a pointer to the \a property and the
  4016. new \a names as parameters.
  4017. \sa setFlagNames()
  4018. */
  4019. /*!
  4020. Creates a manager with the given \a parent.
  4021. */
  4022. QtFlagPropertyManager::QtFlagPropertyManager(QObject *parent)
  4023. : QtAbstractPropertyManager(parent), d_ptr(new QtFlagPropertyManagerPrivate)
  4024. {
  4025. d_ptr->q_ptr = this;
  4026. d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
  4027. connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*,bool)),
  4028. this, SLOT(slotBoolChanged(QtProperty*,bool)));
  4029. connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  4030. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  4031. }
  4032. /*!
  4033. Destroys this manager, and all the properties it has created.
  4034. */
  4035. QtFlagPropertyManager::~QtFlagPropertyManager()
  4036. {
  4037. clear();
  4038. }
  4039. /*!
  4040. Returns the manager that produces the nested boolean subproperties
  4041. representing each flag.
  4042. In order to provide editing widgets for the subproperties in a
  4043. property browser widget, this manager must be associated with an
  4044. editor factory.
  4045. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  4046. */
  4047. QtBoolPropertyManager *QtFlagPropertyManager::subBoolPropertyManager() const
  4048. {
  4049. return d_ptr->m_boolPropertyManager;
  4050. }
  4051. /*!
  4052. Returns the given \a property's value.
  4053. If the given property is not managed by this manager, this
  4054. function returns 0.
  4055. \sa flagNames(), setValue()
  4056. */
  4057. int QtFlagPropertyManager::value(const QtProperty *property) const
  4058. {
  4059. return getValue<int>(d_ptr->m_values, property, 0);
  4060. }
  4061. /*!
  4062. Returns the given \a property's list of flag names.
  4063. \sa value(), setFlagNames()
  4064. */
  4065. QStringList QtFlagPropertyManager::flagNames(const QtProperty *property) const
  4066. {
  4067. return getData<QStringList>(d_ptr->m_values, &QtFlagPropertyManagerPrivate::Data::flagNames, property, QStringList());
  4068. }
  4069. /*!
  4070. \reimp
  4071. */
  4072. QString QtFlagPropertyManager::valueText(const QtProperty *property) const
  4073. {
  4074. const QtFlagPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  4075. if (it == d_ptr->m_values.constEnd())
  4076. return QString();
  4077. const QtFlagPropertyManagerPrivate::Data &data = it.value();
  4078. QString str;
  4079. int level = 0;
  4080. const QChar bar = QLatin1Char('|');
  4081. const QStringList::const_iterator fncend = data.flagNames.constEnd();
  4082. for (QStringList::const_iterator it = data.flagNames.constBegin(); it != fncend; ++it) {
  4083. if (data.val & (1 << level)) {
  4084. if (!str.isEmpty())
  4085. str += bar;
  4086. str += *it;
  4087. }
  4088. level++;
  4089. }
  4090. return str;
  4091. }
  4092. /*!
  4093. \fn void QtFlagPropertyManager::setValue(QtProperty *property, int value)
  4094. Sets the value of the given \a property to \a value. Nested
  4095. properties are updated automatically.
  4096. The specified \a value must be less than the binary combination of
  4097. the property's flagNames() list size (i.e. less than 2\sup n,
  4098. where \c n is the size of the list) and larger than (or equal to)
  4099. 0.
  4100. \sa value(), valueChanged()
  4101. */
  4102. void QtFlagPropertyManager::setValue(QtProperty *property, int val)
  4103. {
  4104. const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  4105. if (it == d_ptr->m_values.end())
  4106. return;
  4107. QtFlagPropertyManagerPrivate::Data data = it.value();
  4108. if (data.val == val)
  4109. return;
  4110. if (val > (1 << data.flagNames.count()) - 1)
  4111. return;
  4112. if (val < 0)
  4113. return;
  4114. data.val = val;
  4115. it.value() = data;
  4116. const auto pfit = d_ptr->m_propertyToFlags.constFind(property);
  4117. int level = 0;
  4118. if (pfit != d_ptr->m_propertyToFlags.constEnd()) {
  4119. for (QtProperty *prop : pfit.value()) {
  4120. if (prop)
  4121. d_ptr->m_boolPropertyManager->setValue(prop, val & (1 << level));
  4122. level++;
  4123. }
  4124. }
  4125. emit propertyChanged(property);
  4126. emit valueChanged(property, data.val);
  4127. }
  4128. /*!
  4129. Sets the given \a property's list of flag names to \a flagNames. The
  4130. property's current value is reset to 0 indicating the first item
  4131. of the list.
  4132. \sa flagNames(), flagNamesChanged()
  4133. */
  4134. void QtFlagPropertyManager::setFlagNames(QtProperty *property, const QStringList &flagNames)
  4135. {
  4136. const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  4137. if (it == d_ptr->m_values.end())
  4138. return;
  4139. QtFlagPropertyManagerPrivate::Data data = it.value();
  4140. if (data.flagNames == flagNames)
  4141. return;
  4142. data.flagNames = flagNames;
  4143. data.val = 0;
  4144. it.value() = data;
  4145. const auto pfit = d_ptr->m_propertyToFlags.find(property);
  4146. if (pfit != d_ptr->m_propertyToFlags.end()) {
  4147. for (QtProperty *prop : qAsConst(pfit.value())) {
  4148. if (prop) {
  4149. delete prop;
  4150. d_ptr->m_flagToProperty.remove(prop);
  4151. }
  4152. }
  4153. pfit.value().clear();
  4154. }
  4155. for (const QString &flagName : flagNames) {
  4156. QtProperty *prop = d_ptr->m_boolPropertyManager->addProperty();
  4157. prop->setPropertyName(flagName);
  4158. property->addSubProperty(prop);
  4159. d_ptr->m_propertyToFlags[property].append(prop);
  4160. d_ptr->m_flagToProperty[prop] = property;
  4161. }
  4162. emit flagNamesChanged(property, data.flagNames);
  4163. emit propertyChanged(property);
  4164. emit valueChanged(property, data.val);
  4165. }
  4166. /*!
  4167. \reimp
  4168. */
  4169. void QtFlagPropertyManager::initializeProperty(QtProperty *property)
  4170. {
  4171. d_ptr->m_values[property] = QtFlagPropertyManagerPrivate::Data();
  4172. d_ptr->m_propertyToFlags[property] = QList<QtProperty *>();
  4173. }
  4174. /*!
  4175. \reimp
  4176. */
  4177. void QtFlagPropertyManager::uninitializeProperty(QtProperty *property)
  4178. {
  4179. const auto it = d_ptr->m_propertyToFlags.find(property);
  4180. if (it != d_ptr->m_propertyToFlags.end()) {
  4181. for (QtProperty *prop : qAsConst(it.value())) {
  4182. if (prop) {
  4183. d_ptr->m_flagToProperty.remove(prop);
  4184. delete prop;
  4185. }
  4186. }
  4187. }
  4188. d_ptr->m_propertyToFlags.erase(it);
  4189. d_ptr->m_values.remove(property);
  4190. }
  4191. // QtSizePolicyPropertyManager
  4192. class QtSizePolicyPropertyManagerPrivate
  4193. {
  4194. QtSizePolicyPropertyManager *q_ptr;
  4195. Q_DECLARE_PUBLIC(QtSizePolicyPropertyManager)
  4196. public:
  4197. QtSizePolicyPropertyManagerPrivate();
  4198. void slotIntChanged(QtProperty *property, int value);
  4199. void slotEnumChanged(QtProperty *property, int value);
  4200. void slotPropertyDestroyed(QtProperty *property);
  4201. typedef QMap<const QtProperty *, QSizePolicy> PropertyValueMap;
  4202. PropertyValueMap m_values;
  4203. QtIntPropertyManager *m_intPropertyManager;
  4204. QtEnumPropertyManager *m_enumPropertyManager;
  4205. QMap<const QtProperty *, QtProperty *> m_propertyToHPolicy;
  4206. QMap<const QtProperty *, QtProperty *> m_propertyToVPolicy;
  4207. QMap<const QtProperty *, QtProperty *> m_propertyToHStretch;
  4208. QMap<const QtProperty *, QtProperty *> m_propertyToVStretch;
  4209. QMap<const QtProperty *, QtProperty *> m_hPolicyToProperty;
  4210. QMap<const QtProperty *, QtProperty *> m_vPolicyToProperty;
  4211. QMap<const QtProperty *, QtProperty *> m_hStretchToProperty;
  4212. QMap<const QtProperty *, QtProperty *> m_vStretchToProperty;
  4213. };
  4214. QtSizePolicyPropertyManagerPrivate::QtSizePolicyPropertyManagerPrivate()
  4215. {
  4216. }
  4217. void QtSizePolicyPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
  4218. {
  4219. if (QtProperty *prop = m_hStretchToProperty.value(property, 0)) {
  4220. QSizePolicy sp = m_values[prop];
  4221. sp.setHorizontalStretch(value);
  4222. q_ptr->setValue(prop, sp);
  4223. } else if (QtProperty *prop = m_vStretchToProperty.value(property, 0)) {
  4224. QSizePolicy sp = m_values[prop];
  4225. sp.setVerticalStretch(value);
  4226. q_ptr->setValue(prop, sp);
  4227. }
  4228. }
  4229. void QtSizePolicyPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
  4230. {
  4231. if (QtProperty *prop = m_hPolicyToProperty.value(property, 0)) {
  4232. QSizePolicy sp = m_values[prop];
  4233. sp.setHorizontalPolicy(metaEnumProvider()->indexToSizePolicy(value));
  4234. q_ptr->setValue(prop, sp);
  4235. } else if (QtProperty *prop = m_vPolicyToProperty.value(property, 0)) {
  4236. QSizePolicy sp = m_values[prop];
  4237. sp.setVerticalPolicy(metaEnumProvider()->indexToSizePolicy(value));
  4238. q_ptr->setValue(prop, sp);
  4239. }
  4240. }
  4241. void QtSizePolicyPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
  4242. {
  4243. if (QtProperty *pointProp = m_hStretchToProperty.value(property, 0)) {
  4244. m_propertyToHStretch[pointProp] = 0;
  4245. m_hStretchToProperty.remove(property);
  4246. } else if (QtProperty *pointProp = m_vStretchToProperty.value(property, 0)) {
  4247. m_propertyToVStretch[pointProp] = 0;
  4248. m_vStretchToProperty.remove(property);
  4249. } else if (QtProperty *pointProp = m_hPolicyToProperty.value(property, 0)) {
  4250. m_propertyToHPolicy[pointProp] = 0;
  4251. m_hPolicyToProperty.remove(property);
  4252. } else if (QtProperty *pointProp = m_vPolicyToProperty.value(property, 0)) {
  4253. m_propertyToVPolicy[pointProp] = 0;
  4254. m_vPolicyToProperty.remove(property);
  4255. }
  4256. }
  4257. /*!
  4258. \class QtSizePolicyPropertyManager
  4259. \internal
  4260. \inmodule QtDesigner
  4261. \since 4.4
  4262. \brief The QtSizePolicyPropertyManager provides and manages QSizePolicy properties.
  4263. A size policy property has nested \e horizontalPolicy, \e
  4264. verticalPolicy, \e horizontalStretch and \e verticalStretch
  4265. subproperties. The top-level property's value can be retrieved
  4266. using the value() function, and set using the setValue() slot.
  4267. The subproperties are created by QtIntPropertyManager and QtEnumPropertyManager
  4268. objects. These managers can be retrieved using the subIntPropertyManager()
  4269. and subEnumPropertyManager() functions respectively. In order to provide
  4270. editing widgets for the subproperties in a property browser widget,
  4271. these managers must be associated with editor factories.
  4272. In addition, QtSizePolicyPropertyManager provides the valueChanged()
  4273. signal which is emitted whenever a property created by this
  4274. manager changes.
  4275. \sa QtAbstractPropertyManager, QtIntPropertyManager, QtEnumPropertyManager
  4276. */
  4277. /*!
  4278. \fn void QtSizePolicyPropertyManager::valueChanged(QtProperty *property, const QSizePolicy &value)
  4279. This signal is emitted whenever a property created by this manager
  4280. changes its value, passing a pointer to the \a property and the
  4281. new \a value as parameters.
  4282. \sa setValue()
  4283. */
  4284. /*!
  4285. Creates a manager with the given \a parent.
  4286. */
  4287. QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject *parent)
  4288. : QtAbstractPropertyManager(parent), d_ptr(new QtSizePolicyPropertyManagerPrivate)
  4289. {
  4290. d_ptr->q_ptr = this;
  4291. d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
  4292. connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  4293. this, SLOT(slotIntChanged(QtProperty*,int)));
  4294. d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
  4295. connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  4296. this, SLOT(slotEnumChanged(QtProperty*,int)));
  4297. connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  4298. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  4299. connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  4300. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  4301. }
  4302. /*!
  4303. Destroys this manager, and all the properties it has created.
  4304. */
  4305. QtSizePolicyPropertyManager::~QtSizePolicyPropertyManager()
  4306. {
  4307. clear();
  4308. }
  4309. /*!
  4310. Returns the manager that creates the nested \e horizontalStretch
  4311. and \e verticalStretch subproperties.
  4312. In order to provide editing widgets for the mentioned subproperties
  4313. in a property browser widget, this manager must be associated with
  4314. an editor factory.
  4315. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  4316. */
  4317. QtIntPropertyManager *QtSizePolicyPropertyManager::subIntPropertyManager() const
  4318. {
  4319. return d_ptr->m_intPropertyManager;
  4320. }
  4321. /*!
  4322. Returns the manager that creates the nested \e horizontalPolicy
  4323. and \e verticalPolicy subproperties.
  4324. In order to provide editing widgets for the mentioned subproperties
  4325. in a property browser widget, this manager must be associated with
  4326. an editor factory.
  4327. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  4328. */
  4329. QtEnumPropertyManager *QtSizePolicyPropertyManager::subEnumPropertyManager() const
  4330. {
  4331. return d_ptr->m_enumPropertyManager;
  4332. }
  4333. /*!
  4334. Returns the given \a property's value.
  4335. If the given property is not managed by this manager, this
  4336. function returns the default size policy.
  4337. \sa setValue()
  4338. */
  4339. QSizePolicy QtSizePolicyPropertyManager::value(const QtProperty *property) const
  4340. {
  4341. return d_ptr->m_values.value(property, QSizePolicy());
  4342. }
  4343. /*!
  4344. \reimp
  4345. */
  4346. QString QtSizePolicyPropertyManager::valueText(const QtProperty *property) const
  4347. {
  4348. const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  4349. if (it == d_ptr->m_values.constEnd())
  4350. return QString();
  4351. const QSizePolicy sp = it.value();
  4352. const QtMetaEnumProvider *mep = metaEnumProvider();
  4353. const int hIndex = mep->sizePolicyToIndex(sp.horizontalPolicy());
  4354. const int vIndex = mep->sizePolicyToIndex(sp.verticalPolicy());
  4355. //! Unknown size policy on reading invalid uic3 files
  4356. const QString hPolicy = hIndex != -1 ? mep->policyEnumNames().at(hIndex) : tr("<Invalid>");
  4357. const QString vPolicy = vIndex != -1 ? mep->policyEnumNames().at(vIndex) : tr("<Invalid>");
  4358. const QString str = tr("[%1, %2, %3, %4]").arg(hPolicy, vPolicy).arg(sp.horizontalStretch()).arg(sp.verticalStretch());
  4359. return str;
  4360. }
  4361. /*!
  4362. \fn void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &value)
  4363. Sets the value of the given \a property to \a value. Nested
  4364. properties are updated automatically.
  4365. \sa value(), valueChanged()
  4366. */
  4367. void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &val)
  4368. {
  4369. const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  4370. if (it == d_ptr->m_values.end())
  4371. return;
  4372. if (it.value() == val)
  4373. return;
  4374. it.value() = val;
  4375. d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToHPolicy[property],
  4376. metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
  4377. d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToVPolicy[property],
  4378. metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
  4379. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToHStretch[property],
  4380. val.horizontalStretch());
  4381. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToVStretch[property],
  4382. val.verticalStretch());
  4383. emit propertyChanged(property);
  4384. emit valueChanged(property, val);
  4385. }
  4386. /*!
  4387. \reimp
  4388. */
  4389. void QtSizePolicyPropertyManager::initializeProperty(QtProperty *property)
  4390. {
  4391. QSizePolicy val;
  4392. d_ptr->m_values[property] = val;
  4393. QtProperty *hPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
  4394. hPolicyProp->setPropertyName(tr("Horizontal Policy"));
  4395. d_ptr->m_enumPropertyManager->setEnumNames(hPolicyProp, metaEnumProvider()->policyEnumNames());
  4396. d_ptr->m_enumPropertyManager->setValue(hPolicyProp,
  4397. metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
  4398. d_ptr->m_propertyToHPolicy[property] = hPolicyProp;
  4399. d_ptr->m_hPolicyToProperty[hPolicyProp] = property;
  4400. property->addSubProperty(hPolicyProp);
  4401. QtProperty *vPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
  4402. vPolicyProp->setPropertyName(tr("Vertical Policy"));
  4403. d_ptr->m_enumPropertyManager->setEnumNames(vPolicyProp, metaEnumProvider()->policyEnumNames());
  4404. d_ptr->m_enumPropertyManager->setValue(vPolicyProp,
  4405. metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
  4406. d_ptr->m_propertyToVPolicy[property] = vPolicyProp;
  4407. d_ptr->m_vPolicyToProperty[vPolicyProp] = property;
  4408. property->addSubProperty(vPolicyProp);
  4409. QtProperty *hStretchProp = d_ptr->m_intPropertyManager->addProperty();
  4410. hStretchProp->setPropertyName(tr("Horizontal Stretch"));
  4411. d_ptr->m_intPropertyManager->setValue(hStretchProp, val.horizontalStretch());
  4412. d_ptr->m_intPropertyManager->setRange(hStretchProp, 0, 0xff);
  4413. d_ptr->m_propertyToHStretch[property] = hStretchProp;
  4414. d_ptr->m_hStretchToProperty[hStretchProp] = property;
  4415. property->addSubProperty(hStretchProp);
  4416. QtProperty *vStretchProp = d_ptr->m_intPropertyManager->addProperty();
  4417. vStretchProp->setPropertyName(tr("Vertical Stretch"));
  4418. d_ptr->m_intPropertyManager->setValue(vStretchProp, val.verticalStretch());
  4419. d_ptr->m_intPropertyManager->setRange(vStretchProp, 0, 0xff);
  4420. d_ptr->m_propertyToVStretch[property] = vStretchProp;
  4421. d_ptr->m_vStretchToProperty[vStretchProp] = property;
  4422. property->addSubProperty(vStretchProp);
  4423. }
  4424. /*!
  4425. \reimp
  4426. */
  4427. void QtSizePolicyPropertyManager::uninitializeProperty(QtProperty *property)
  4428. {
  4429. QtProperty *hPolicyProp = d_ptr->m_propertyToHPolicy[property];
  4430. if (hPolicyProp) {
  4431. d_ptr->m_hPolicyToProperty.remove(hPolicyProp);
  4432. delete hPolicyProp;
  4433. }
  4434. d_ptr->m_propertyToHPolicy.remove(property);
  4435. QtProperty *vPolicyProp = d_ptr->m_propertyToVPolicy[property];
  4436. if (vPolicyProp) {
  4437. d_ptr->m_vPolicyToProperty.remove(vPolicyProp);
  4438. delete vPolicyProp;
  4439. }
  4440. d_ptr->m_propertyToVPolicy.remove(property);
  4441. QtProperty *hStretchProp = d_ptr->m_propertyToHStretch[property];
  4442. if (hStretchProp) {
  4443. d_ptr->m_hStretchToProperty.remove(hStretchProp);
  4444. delete hStretchProp;
  4445. }
  4446. d_ptr->m_propertyToHStretch.remove(property);
  4447. QtProperty *vStretchProp = d_ptr->m_propertyToVStretch[property];
  4448. if (vStretchProp) {
  4449. d_ptr->m_vStretchToProperty.remove(vStretchProp);
  4450. delete vStretchProp;
  4451. }
  4452. d_ptr->m_propertyToVStretch.remove(property);
  4453. d_ptr->m_values.remove(property);
  4454. }
  4455. // QtFontPropertyManager:
  4456. // QtFontPropertyManagerPrivate has a mechanism for reacting
  4457. // to QApplication::fontDatabaseChanged() [4.5], which is emitted
  4458. // when someone loads an application font. The signals are compressed
  4459. // using a timer with interval 0, which then causes the family
  4460. // enumeration manager to re-set its strings and index values
  4461. // for each property.
  4462. Q_GLOBAL_STATIC(QFontDatabase, fontDatabase)
  4463. class QtFontPropertyManagerPrivate
  4464. {
  4465. QtFontPropertyManager *q_ptr;
  4466. Q_DECLARE_PUBLIC(QtFontPropertyManager)
  4467. public:
  4468. QtFontPropertyManagerPrivate();
  4469. void slotIntChanged(QtProperty *property, int value);
  4470. void slotEnumChanged(QtProperty *property, int value);
  4471. void slotBoolChanged(QtProperty *property, bool value);
  4472. void slotPropertyDestroyed(QtProperty *property);
  4473. void slotFontDatabaseChanged();
  4474. void slotFontDatabaseDelayedChange();
  4475. QStringList m_familyNames;
  4476. typedef QMap<const QtProperty *, QFont> PropertyValueMap;
  4477. PropertyValueMap m_values;
  4478. QtIntPropertyManager *m_intPropertyManager;
  4479. QtEnumPropertyManager *m_enumPropertyManager;
  4480. QtBoolPropertyManager *m_boolPropertyManager;
  4481. QMap<const QtProperty *, QtProperty *> m_propertyToFamily;
  4482. QMap<const QtProperty *, QtProperty *> m_propertyToPointSize;
  4483. QMap<const QtProperty *, QtProperty *> m_propertyToBold;
  4484. QMap<const QtProperty *, QtProperty *> m_propertyToItalic;
  4485. QMap<const QtProperty *, QtProperty *> m_propertyToUnderline;
  4486. QMap<const QtProperty *, QtProperty *> m_propertyToStrikeOut;
  4487. QMap<const QtProperty *, QtProperty *> m_propertyToKerning;
  4488. QMap<const QtProperty *, QtProperty *> m_familyToProperty;
  4489. QMap<const QtProperty *, QtProperty *> m_pointSizeToProperty;
  4490. QMap<const QtProperty *, QtProperty *> m_boldToProperty;
  4491. QMap<const QtProperty *, QtProperty *> m_italicToProperty;
  4492. QMap<const QtProperty *, QtProperty *> m_underlineToProperty;
  4493. QMap<const QtProperty *, QtProperty *> m_strikeOutToProperty;
  4494. QMap<const QtProperty *, QtProperty *> m_kerningToProperty;
  4495. bool m_settingValue;
  4496. QTimer *m_fontDatabaseChangeTimer;
  4497. };
  4498. QtFontPropertyManagerPrivate::QtFontPropertyManagerPrivate() :
  4499. m_settingValue(false),
  4500. m_fontDatabaseChangeTimer(0)
  4501. {
  4502. }
  4503. void QtFontPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
  4504. {
  4505. if (m_settingValue)
  4506. return;
  4507. if (QtProperty *prop = m_pointSizeToProperty.value(property, 0)) {
  4508. QFont f = m_values[prop];
  4509. f.setPointSize(value);
  4510. q_ptr->setValue(prop, f);
  4511. }
  4512. }
  4513. void QtFontPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
  4514. {
  4515. if (m_settingValue)
  4516. return;
  4517. if (QtProperty *prop = m_familyToProperty.value(property, 0)) {
  4518. QFont f = m_values[prop];
  4519. f.setFamily(m_familyNames.at(value));
  4520. q_ptr->setValue(prop, f);
  4521. }
  4522. }
  4523. void QtFontPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
  4524. {
  4525. if (m_settingValue)
  4526. return;
  4527. if (QtProperty *prop = m_boldToProperty.value(property, 0)) {
  4528. QFont f = m_values[prop];
  4529. f.setBold(value);
  4530. q_ptr->setValue(prop, f);
  4531. } else if (QtProperty *prop = m_italicToProperty.value(property, 0)) {
  4532. QFont f = m_values[prop];
  4533. f.setItalic(value);
  4534. q_ptr->setValue(prop, f);
  4535. } else if (QtProperty *prop = m_underlineToProperty.value(property, 0)) {
  4536. QFont f = m_values[prop];
  4537. f.setUnderline(value);
  4538. q_ptr->setValue(prop, f);
  4539. } else if (QtProperty *prop = m_strikeOutToProperty.value(property, 0)) {
  4540. QFont f = m_values[prop];
  4541. f.setStrikeOut(value);
  4542. q_ptr->setValue(prop, f);
  4543. } else if (QtProperty *prop = m_kerningToProperty.value(property, 0)) {
  4544. QFont f = m_values[prop];
  4545. f.setKerning(value);
  4546. q_ptr->setValue(prop, f);
  4547. }
  4548. }
  4549. void QtFontPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
  4550. {
  4551. if (QtProperty *pointProp = m_pointSizeToProperty.value(property, 0)) {
  4552. m_propertyToPointSize[pointProp] = 0;
  4553. m_pointSizeToProperty.remove(property);
  4554. } else if (QtProperty *pointProp = m_familyToProperty.value(property, 0)) {
  4555. m_propertyToFamily[pointProp] = 0;
  4556. m_familyToProperty.remove(property);
  4557. } else if (QtProperty *pointProp = m_boldToProperty.value(property, 0)) {
  4558. m_propertyToBold[pointProp] = 0;
  4559. m_boldToProperty.remove(property);
  4560. } else if (QtProperty *pointProp = m_italicToProperty.value(property, 0)) {
  4561. m_propertyToItalic[pointProp] = 0;
  4562. m_italicToProperty.remove(property);
  4563. } else if (QtProperty *pointProp = m_underlineToProperty.value(property, 0)) {
  4564. m_propertyToUnderline[pointProp] = 0;
  4565. m_underlineToProperty.remove(property);
  4566. } else if (QtProperty *pointProp = m_strikeOutToProperty.value(property, 0)) {
  4567. m_propertyToStrikeOut[pointProp] = 0;
  4568. m_strikeOutToProperty.remove(property);
  4569. } else if (QtProperty *pointProp = m_kerningToProperty.value(property, 0)) {
  4570. m_propertyToKerning[pointProp] = 0;
  4571. m_kerningToProperty.remove(property);
  4572. }
  4573. }
  4574. void QtFontPropertyManagerPrivate::slotFontDatabaseChanged()
  4575. {
  4576. if (!m_fontDatabaseChangeTimer) {
  4577. m_fontDatabaseChangeTimer = new QTimer(q_ptr);
  4578. m_fontDatabaseChangeTimer->setInterval(0);
  4579. m_fontDatabaseChangeTimer->setSingleShot(true);
  4580. QObject::connect(m_fontDatabaseChangeTimer, SIGNAL(timeout()), q_ptr, SLOT(slotFontDatabaseDelayedChange()));
  4581. }
  4582. if (!m_fontDatabaseChangeTimer->isActive())
  4583. m_fontDatabaseChangeTimer->start();
  4584. }
  4585. void QtFontPropertyManagerPrivate::slotFontDatabaseDelayedChange()
  4586. {
  4587. typedef QMap<const QtProperty *, QtProperty *> PropertyPropertyMap;
  4588. // rescan available font names
  4589. const QStringList oldFamilies = m_familyNames;
  4590. m_familyNames = fontDatabase()->families();
  4591. // Adapt all existing properties
  4592. if (!m_propertyToFamily.empty()) {
  4593. PropertyPropertyMap::const_iterator cend = m_propertyToFamily.constEnd();
  4594. for (PropertyPropertyMap::const_iterator it = m_propertyToFamily.constBegin(); it != cend; ++it) {
  4595. QtProperty *familyProp = it.value();
  4596. const int oldIdx = m_enumPropertyManager->value(familyProp);
  4597. int newIdx = m_familyNames.indexOf(oldFamilies.at(oldIdx));
  4598. if (newIdx < 0)
  4599. newIdx = 0;
  4600. m_enumPropertyManager->setEnumNames(familyProp, m_familyNames);
  4601. m_enumPropertyManager->setValue(familyProp, newIdx);
  4602. }
  4603. }
  4604. }
  4605. /*!
  4606. \class QtFontPropertyManager
  4607. \internal
  4608. \inmodule QtDesigner
  4609. \since 4.4
  4610. \brief The QtFontPropertyManager provides and manages QFont properties.
  4611. A font property has nested \e family, \e pointSize, \e bold, \e
  4612. italic, \e underline, \e strikeOut and \e kerning subproperties. The top-level
  4613. property's value can be retrieved using the value() function, and
  4614. set using the setValue() slot.
  4615. The subproperties are created by QtIntPropertyManager, QtEnumPropertyManager and
  4616. QtBoolPropertyManager objects. These managers can be retrieved using the
  4617. corresponding subIntPropertyManager(), subEnumPropertyManager() and
  4618. subBoolPropertyManager() functions. In order to provide editing widgets
  4619. for the subproperties in a property browser widget, these managers
  4620. must be associated with editor factories.
  4621. In addition, QtFontPropertyManager provides the valueChanged() signal
  4622. which is emitted whenever a property created by this manager
  4623. changes.
  4624. \sa QtAbstractPropertyManager, QtEnumPropertyManager, QtIntPropertyManager, QtBoolPropertyManager
  4625. */
  4626. /*!
  4627. \fn void QtFontPropertyManager::valueChanged(QtProperty *property, const QFont &value)
  4628. This signal is emitted whenever a property created by this manager
  4629. changes its value, passing a pointer to the \a property and the
  4630. new \a value as parameters.
  4631. \sa setValue()
  4632. */
  4633. /*!
  4634. Creates a manager with the given \a parent.
  4635. */
  4636. QtFontPropertyManager::QtFontPropertyManager(QObject *parent)
  4637. : QtAbstractPropertyManager(parent), d_ptr(new QtFontPropertyManagerPrivate)
  4638. {
  4639. d_ptr->q_ptr = this;
  4640. QObject::connect(qApp, SIGNAL(fontDatabaseChanged()), this, SLOT(slotFontDatabaseChanged()));
  4641. d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
  4642. connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  4643. this, SLOT(slotIntChanged(QtProperty*,int)));
  4644. d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
  4645. connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  4646. this, SLOT(slotEnumChanged(QtProperty*,int)));
  4647. d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
  4648. connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*,bool)),
  4649. this, SLOT(slotBoolChanged(QtProperty*,bool)));
  4650. connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  4651. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  4652. connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  4653. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  4654. connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  4655. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  4656. }
  4657. /*!
  4658. Destroys this manager, and all the properties it has created.
  4659. */
  4660. QtFontPropertyManager::~QtFontPropertyManager()
  4661. {
  4662. clear();
  4663. }
  4664. /*!
  4665. Returns the manager that creates the \e pointSize subproperty.
  4666. In order to provide editing widgets for the \e pointSize property
  4667. in a property browser widget, this manager must be associated
  4668. with an editor factory.
  4669. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  4670. */
  4671. QtIntPropertyManager *QtFontPropertyManager::subIntPropertyManager() const
  4672. {
  4673. return d_ptr->m_intPropertyManager;
  4674. }
  4675. /*!
  4676. Returns the manager that create the \e family subproperty.
  4677. In order to provide editing widgets for the \e family property
  4678. in a property browser widget, this manager must be associated
  4679. with an editor factory.
  4680. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  4681. */
  4682. QtEnumPropertyManager *QtFontPropertyManager::subEnumPropertyManager() const
  4683. {
  4684. return d_ptr->m_enumPropertyManager;
  4685. }
  4686. /*!
  4687. Returns the manager that creates the \e bold, \e italic, \e underline,
  4688. \e strikeOut and \e kerning subproperties.
  4689. In order to provide editing widgets for the mentioned properties
  4690. in a property browser widget, this manager must be associated with
  4691. an editor factory.
  4692. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  4693. */
  4694. QtBoolPropertyManager *QtFontPropertyManager::subBoolPropertyManager() const
  4695. {
  4696. return d_ptr->m_boolPropertyManager;
  4697. }
  4698. /*!
  4699. Returns the given \a property's value.
  4700. If the given property is not managed by this manager, this
  4701. function returns a font object that uses the application's default
  4702. font.
  4703. \sa setValue()
  4704. */
  4705. QFont QtFontPropertyManager::value(const QtProperty *property) const
  4706. {
  4707. return d_ptr->m_values.value(property, QFont());
  4708. }
  4709. /*!
  4710. \reimp
  4711. */
  4712. QString QtFontPropertyManager::valueText(const QtProperty *property) const
  4713. {
  4714. const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  4715. if (it == d_ptr->m_values.constEnd())
  4716. return QString();
  4717. return QtPropertyBrowserUtils::fontValueText(it.value());
  4718. }
  4719. /*!
  4720. \reimp
  4721. */
  4722. QIcon QtFontPropertyManager::valueIcon(const QtProperty *property) const
  4723. {
  4724. const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  4725. if (it == d_ptr->m_values.constEnd())
  4726. return QIcon();
  4727. return QtPropertyBrowserUtils::fontValueIcon(it.value());
  4728. }
  4729. /*!
  4730. \fn void QtFontPropertyManager::setValue(QtProperty *property, const QFont &value)
  4731. Sets the value of the given \a property to \a value. Nested
  4732. properties are updated automatically.
  4733. \sa value(), valueChanged()
  4734. */
  4735. void QtFontPropertyManager::setValue(QtProperty *property, const QFont &val)
  4736. {
  4737. const QtFontPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  4738. if (it == d_ptr->m_values.end())
  4739. return;
  4740. const QFont oldVal = it.value();
  4741. if (oldVal == val && oldVal.resolve() == val.resolve())
  4742. return;
  4743. it.value() = val;
  4744. int idx = d_ptr->m_familyNames.indexOf(val.family());
  4745. if (idx == -1)
  4746. idx = 0;
  4747. bool settingValue = d_ptr->m_settingValue;
  4748. d_ptr->m_settingValue = true;
  4749. d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToFamily[property], idx);
  4750. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToPointSize[property], val.pointSize());
  4751. d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToBold[property], val.bold());
  4752. d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToItalic[property], val.italic());
  4753. d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToUnderline[property], val.underline());
  4754. d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToStrikeOut[property], val.strikeOut());
  4755. d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToKerning[property], val.kerning());
  4756. d_ptr->m_settingValue = settingValue;
  4757. emit propertyChanged(property);
  4758. emit valueChanged(property, val);
  4759. }
  4760. /*!
  4761. \reimp
  4762. */
  4763. void QtFontPropertyManager::initializeProperty(QtProperty *property)
  4764. {
  4765. QFont val;
  4766. d_ptr->m_values[property] = val;
  4767. QtProperty *familyProp = d_ptr->m_enumPropertyManager->addProperty();
  4768. familyProp->setPropertyName(tr("Family"));
  4769. if (d_ptr->m_familyNames.empty())
  4770. d_ptr->m_familyNames = fontDatabase()->families();
  4771. d_ptr->m_enumPropertyManager->setEnumNames(familyProp, d_ptr->m_familyNames);
  4772. int idx = d_ptr->m_familyNames.indexOf(val.family());
  4773. if (idx == -1)
  4774. idx = 0;
  4775. d_ptr->m_enumPropertyManager->setValue(familyProp, idx);
  4776. d_ptr->m_propertyToFamily[property] = familyProp;
  4777. d_ptr->m_familyToProperty[familyProp] = property;
  4778. property->addSubProperty(familyProp);
  4779. QtProperty *pointSizeProp = d_ptr->m_intPropertyManager->addProperty();
  4780. pointSizeProp->setPropertyName(tr("Point Size"));
  4781. d_ptr->m_intPropertyManager->setValue(pointSizeProp, val.pointSize());
  4782. d_ptr->m_intPropertyManager->setMinimum(pointSizeProp, 1);
  4783. d_ptr->m_propertyToPointSize[property] = pointSizeProp;
  4784. d_ptr->m_pointSizeToProperty[pointSizeProp] = property;
  4785. property->addSubProperty(pointSizeProp);
  4786. QtProperty *boldProp = d_ptr->m_boolPropertyManager->addProperty();
  4787. boldProp->setPropertyName(tr("Bold"));
  4788. d_ptr->m_boolPropertyManager->setValue(boldProp, val.bold());
  4789. d_ptr->m_propertyToBold[property] = boldProp;
  4790. d_ptr->m_boldToProperty[boldProp] = property;
  4791. property->addSubProperty(boldProp);
  4792. QtProperty *italicProp = d_ptr->m_boolPropertyManager->addProperty();
  4793. italicProp->setPropertyName(tr("Italic"));
  4794. d_ptr->m_boolPropertyManager->setValue(italicProp, val.italic());
  4795. d_ptr->m_propertyToItalic[property] = italicProp;
  4796. d_ptr->m_italicToProperty[italicProp] = property;
  4797. property->addSubProperty(italicProp);
  4798. QtProperty *underlineProp = d_ptr->m_boolPropertyManager->addProperty();
  4799. underlineProp->setPropertyName(tr("Underline"));
  4800. d_ptr->m_boolPropertyManager->setValue(underlineProp, val.underline());
  4801. d_ptr->m_propertyToUnderline[property] = underlineProp;
  4802. d_ptr->m_underlineToProperty[underlineProp] = property;
  4803. property->addSubProperty(underlineProp);
  4804. QtProperty *strikeOutProp = d_ptr->m_boolPropertyManager->addProperty();
  4805. strikeOutProp->setPropertyName(tr("Strikeout"));
  4806. d_ptr->m_boolPropertyManager->setValue(strikeOutProp, val.strikeOut());
  4807. d_ptr->m_propertyToStrikeOut[property] = strikeOutProp;
  4808. d_ptr->m_strikeOutToProperty[strikeOutProp] = property;
  4809. property->addSubProperty(strikeOutProp);
  4810. QtProperty *kerningProp = d_ptr->m_boolPropertyManager->addProperty();
  4811. kerningProp->setPropertyName(tr("Kerning"));
  4812. d_ptr->m_boolPropertyManager->setValue(kerningProp, val.kerning());
  4813. d_ptr->m_propertyToKerning[property] = kerningProp;
  4814. d_ptr->m_kerningToProperty[kerningProp] = property;
  4815. property->addSubProperty(kerningProp);
  4816. }
  4817. /*!
  4818. \reimp
  4819. */
  4820. void QtFontPropertyManager::uninitializeProperty(QtProperty *property)
  4821. {
  4822. QtProperty *familyProp = d_ptr->m_propertyToFamily[property];
  4823. if (familyProp) {
  4824. d_ptr->m_familyToProperty.remove(familyProp);
  4825. delete familyProp;
  4826. }
  4827. d_ptr->m_propertyToFamily.remove(property);
  4828. QtProperty *pointSizeProp = d_ptr->m_propertyToPointSize[property];
  4829. if (pointSizeProp) {
  4830. d_ptr->m_pointSizeToProperty.remove(pointSizeProp);
  4831. delete pointSizeProp;
  4832. }
  4833. d_ptr->m_propertyToPointSize.remove(property);
  4834. QtProperty *boldProp = d_ptr->m_propertyToBold[property];
  4835. if (boldProp) {
  4836. d_ptr->m_boldToProperty.remove(boldProp);
  4837. delete boldProp;
  4838. }
  4839. d_ptr->m_propertyToBold.remove(property);
  4840. QtProperty *italicProp = d_ptr->m_propertyToItalic[property];
  4841. if (italicProp) {
  4842. d_ptr->m_italicToProperty.remove(italicProp);
  4843. delete italicProp;
  4844. }
  4845. d_ptr->m_propertyToItalic.remove(property);
  4846. QtProperty *underlineProp = d_ptr->m_propertyToUnderline[property];
  4847. if (underlineProp) {
  4848. d_ptr->m_underlineToProperty.remove(underlineProp);
  4849. delete underlineProp;
  4850. }
  4851. d_ptr->m_propertyToUnderline.remove(property);
  4852. QtProperty *strikeOutProp = d_ptr->m_propertyToStrikeOut[property];
  4853. if (strikeOutProp) {
  4854. d_ptr->m_strikeOutToProperty.remove(strikeOutProp);
  4855. delete strikeOutProp;
  4856. }
  4857. d_ptr->m_propertyToStrikeOut.remove(property);
  4858. QtProperty *kerningProp = d_ptr->m_propertyToKerning[property];
  4859. if (kerningProp) {
  4860. d_ptr->m_kerningToProperty.remove(kerningProp);
  4861. delete kerningProp;
  4862. }
  4863. d_ptr->m_propertyToKerning.remove(property);
  4864. d_ptr->m_values.remove(property);
  4865. }
  4866. // QtColorPropertyManager
  4867. class QtColorPropertyManagerPrivate
  4868. {
  4869. QtColorPropertyManager *q_ptr;
  4870. Q_DECLARE_PUBLIC(QtColorPropertyManager)
  4871. public:
  4872. void slotIntChanged(QtProperty *property, int value);
  4873. void slotPropertyDestroyed(QtProperty *property);
  4874. typedef QMap<const QtProperty *, QColor> PropertyValueMap;
  4875. PropertyValueMap m_values;
  4876. QtIntPropertyManager *m_intPropertyManager;
  4877. QMap<const QtProperty *, QtProperty *> m_propertyToR;
  4878. QMap<const QtProperty *, QtProperty *> m_propertyToG;
  4879. QMap<const QtProperty *, QtProperty *> m_propertyToB;
  4880. QMap<const QtProperty *, QtProperty *> m_propertyToA;
  4881. QMap<const QtProperty *, QtProperty *> m_rToProperty;
  4882. QMap<const QtProperty *, QtProperty *> m_gToProperty;
  4883. QMap<const QtProperty *, QtProperty *> m_bToProperty;
  4884. QMap<const QtProperty *, QtProperty *> m_aToProperty;
  4885. };
  4886. void QtColorPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
  4887. {
  4888. if (QtProperty *prop = m_rToProperty.value(property, 0)) {
  4889. QColor c = m_values[prop];
  4890. c.setRed(value);
  4891. q_ptr->setValue(prop, c);
  4892. } else if (QtProperty *prop = m_gToProperty.value(property, 0)) {
  4893. QColor c = m_values[prop];
  4894. c.setGreen(value);
  4895. q_ptr->setValue(prop, c);
  4896. } else if (QtProperty *prop = m_bToProperty.value(property, 0)) {
  4897. QColor c = m_values[prop];
  4898. c.setBlue(value);
  4899. q_ptr->setValue(prop, c);
  4900. } else if (QtProperty *prop = m_aToProperty.value(property, 0)) {
  4901. QColor c = m_values[prop];
  4902. c.setAlpha(value);
  4903. q_ptr->setValue(prop, c);
  4904. }
  4905. }
  4906. void QtColorPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
  4907. {
  4908. if (QtProperty *pointProp = m_rToProperty.value(property, 0)) {
  4909. m_propertyToR[pointProp] = 0;
  4910. m_rToProperty.remove(property);
  4911. } else if (QtProperty *pointProp = m_gToProperty.value(property, 0)) {
  4912. m_propertyToG[pointProp] = 0;
  4913. m_gToProperty.remove(property);
  4914. } else if (QtProperty *pointProp = m_bToProperty.value(property, 0)) {
  4915. m_propertyToB[pointProp] = 0;
  4916. m_bToProperty.remove(property);
  4917. } else if (QtProperty *pointProp = m_aToProperty.value(property, 0)) {
  4918. m_propertyToA[pointProp] = 0;
  4919. m_aToProperty.remove(property);
  4920. }
  4921. }
  4922. /*!
  4923. \class QtColorPropertyManager
  4924. \internal
  4925. \inmodule QtDesigner
  4926. \since 4.4
  4927. \brief The QtColorPropertyManager provides and manages QColor properties.
  4928. A color property has nested \e red, \e green and \e blue
  4929. subproperties. The top-level property's value can be retrieved
  4930. using the value() function, and set using the setValue() slot.
  4931. The subproperties are created by a QtIntPropertyManager object. This
  4932. manager can be retrieved using the subIntPropertyManager() function. In
  4933. order to provide editing widgets for the subproperties in a
  4934. property browser widget, this manager must be associated with an
  4935. editor factory.
  4936. In addition, QtColorPropertyManager provides the valueChanged() signal
  4937. which is emitted whenever a property created by this manager
  4938. changes.
  4939. \sa QtAbstractPropertyManager, QtAbstractPropertyBrowser, QtIntPropertyManager
  4940. */
  4941. /*!
  4942. \fn void QtColorPropertyManager::valueChanged(QtProperty *property, const QColor &value)
  4943. This signal is emitted whenever a property created by this manager
  4944. changes its value, passing a pointer to the \a property and the new
  4945. \a value as parameters.
  4946. \sa setValue()
  4947. */
  4948. /*!
  4949. Creates a manager with the given \a parent.
  4950. */
  4951. QtColorPropertyManager::QtColorPropertyManager(QObject *parent)
  4952. : QtAbstractPropertyManager(parent), d_ptr(new QtColorPropertyManagerPrivate)
  4953. {
  4954. d_ptr->q_ptr = this;
  4955. d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
  4956. connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  4957. this, SLOT(slotIntChanged(QtProperty*,int)));
  4958. connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
  4959. this, SLOT(slotPropertyDestroyed(QtProperty*)));
  4960. }
  4961. /*!
  4962. Destroys this manager, and all the properties it has created.
  4963. */
  4964. QtColorPropertyManager::~QtColorPropertyManager()
  4965. {
  4966. clear();
  4967. }
  4968. /*!
  4969. Returns the manager that produces the nested \e red, \e green and
  4970. \e blue subproperties.
  4971. In order to provide editing widgets for the subproperties in a
  4972. property browser widget, this manager must be associated with an
  4973. editor factory.
  4974. \sa QtAbstractPropertyBrowser::setFactoryForManager()
  4975. */
  4976. QtIntPropertyManager *QtColorPropertyManager::subIntPropertyManager() const
  4977. {
  4978. return d_ptr->m_intPropertyManager;
  4979. }
  4980. /*!
  4981. Returns the given \a property's value.
  4982. If the given \a property is not managed by \e this manager, this
  4983. function returns an invalid color.
  4984. \sa setValue()
  4985. */
  4986. QColor QtColorPropertyManager::value(const QtProperty *property) const
  4987. {
  4988. return d_ptr->m_values.value(property, QColor());
  4989. }
  4990. /*!
  4991. \reimp
  4992. */
  4993. QString QtColorPropertyManager::valueText(const QtProperty *property) const
  4994. {
  4995. const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  4996. if (it == d_ptr->m_values.constEnd())
  4997. return QString();
  4998. return QtPropertyBrowserUtils::colorValueText(it.value());
  4999. }
  5000. /*!
  5001. \reimp
  5002. */
  5003. QIcon QtColorPropertyManager::valueIcon(const QtProperty *property) const
  5004. {
  5005. const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  5006. if (it == d_ptr->m_values.constEnd())
  5007. return QIcon();
  5008. return QtPropertyBrowserUtils::brushValueIcon(QBrush(it.value()));
  5009. }
  5010. /*!
  5011. \fn void QtColorPropertyManager::setValue(QtProperty *property, const QColor &value)
  5012. Sets the value of the given \a property to \a value. Nested
  5013. properties are updated automatically.
  5014. \sa value(), valueChanged()
  5015. */
  5016. void QtColorPropertyManager::setValue(QtProperty *property, const QColor &val)
  5017. {
  5018. const QtColorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  5019. if (it == d_ptr->m_values.end())
  5020. return;
  5021. if (it.value() == val)
  5022. return;
  5023. it.value() = val;
  5024. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToR[property], val.red());
  5025. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToG[property], val.green());
  5026. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToB[property], val.blue());
  5027. d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToA[property], val.alpha());
  5028. emit propertyChanged(property);
  5029. emit valueChanged(property, val);
  5030. }
  5031. /*!
  5032. \reimp
  5033. */
  5034. void QtColorPropertyManager::initializeProperty(QtProperty *property)
  5035. {
  5036. QColor val;
  5037. d_ptr->m_values[property] = val;
  5038. QtProperty *rProp = d_ptr->m_intPropertyManager->addProperty();
  5039. rProp->setPropertyName(tr("Red"));
  5040. d_ptr->m_intPropertyManager->setValue(rProp, val.red());
  5041. d_ptr->m_intPropertyManager->setRange(rProp, 0, 0xFF);
  5042. d_ptr->m_propertyToR[property] = rProp;
  5043. d_ptr->m_rToProperty[rProp] = property;
  5044. property->addSubProperty(rProp);
  5045. QtProperty *gProp = d_ptr->m_intPropertyManager->addProperty();
  5046. gProp->setPropertyName(tr("Green"));
  5047. d_ptr->m_intPropertyManager->setValue(gProp, val.green());
  5048. d_ptr->m_intPropertyManager->setRange(gProp, 0, 0xFF);
  5049. d_ptr->m_propertyToG[property] = gProp;
  5050. d_ptr->m_gToProperty[gProp] = property;
  5051. property->addSubProperty(gProp);
  5052. QtProperty *bProp = d_ptr->m_intPropertyManager->addProperty();
  5053. bProp->setPropertyName(tr("Blue"));
  5054. d_ptr->m_intPropertyManager->setValue(bProp, val.blue());
  5055. d_ptr->m_intPropertyManager->setRange(bProp, 0, 0xFF);
  5056. d_ptr->m_propertyToB[property] = bProp;
  5057. d_ptr->m_bToProperty[bProp] = property;
  5058. property->addSubProperty(bProp);
  5059. QtProperty *aProp = d_ptr->m_intPropertyManager->addProperty();
  5060. aProp->setPropertyName(tr("Alpha"));
  5061. d_ptr->m_intPropertyManager->setValue(aProp, val.alpha());
  5062. d_ptr->m_intPropertyManager->setRange(aProp, 0, 0xFF);
  5063. d_ptr->m_propertyToA[property] = aProp;
  5064. d_ptr->m_aToProperty[aProp] = property;
  5065. property->addSubProperty(aProp);
  5066. }
  5067. /*!
  5068. \reimp
  5069. */
  5070. void QtColorPropertyManager::uninitializeProperty(QtProperty *property)
  5071. {
  5072. QtProperty *rProp = d_ptr->m_propertyToR[property];
  5073. if (rProp) {
  5074. d_ptr->m_rToProperty.remove(rProp);
  5075. delete rProp;
  5076. }
  5077. d_ptr->m_propertyToR.remove(property);
  5078. QtProperty *gProp = d_ptr->m_propertyToG[property];
  5079. if (gProp) {
  5080. d_ptr->m_gToProperty.remove(gProp);
  5081. delete gProp;
  5082. }
  5083. d_ptr->m_propertyToG.remove(property);
  5084. QtProperty *bProp = d_ptr->m_propertyToB[property];
  5085. if (bProp) {
  5086. d_ptr->m_bToProperty.remove(bProp);
  5087. delete bProp;
  5088. }
  5089. d_ptr->m_propertyToB.remove(property);
  5090. QtProperty *aProp = d_ptr->m_propertyToA[property];
  5091. if (aProp) {
  5092. d_ptr->m_aToProperty.remove(aProp);
  5093. delete aProp;
  5094. }
  5095. d_ptr->m_propertyToA.remove(property);
  5096. d_ptr->m_values.remove(property);
  5097. }
  5098. // QtCursorPropertyManager
  5099. // Make sure icons are removed as soon as QApplication is destroyed, otherwise,
  5100. // handles are leaked on X11.
  5101. static void clearCursorDatabase();
  5102. namespace {
  5103. struct CursorDatabase : public QtCursorDatabase
  5104. {
  5105. CursorDatabase()
  5106. {
  5107. qAddPostRoutine(clearCursorDatabase);
  5108. }
  5109. };
  5110. }
  5111. Q_GLOBAL_STATIC(QtCursorDatabase, cursorDatabase)
  5112. static void clearCursorDatabase()
  5113. {
  5114. cursorDatabase()->clear();
  5115. }
  5116. class QtCursorPropertyManagerPrivate
  5117. {
  5118. QtCursorPropertyManager *q_ptr;
  5119. Q_DECLARE_PUBLIC(QtCursorPropertyManager)
  5120. public:
  5121. typedef QMap<const QtProperty *, QCursor> PropertyValueMap;
  5122. PropertyValueMap m_values;
  5123. };
  5124. /*!
  5125. \class QtCursorPropertyManager
  5126. \internal
  5127. \inmodule QtDesigner
  5128. \since 4.4
  5129. \brief The QtCursorPropertyManager provides and manages QCursor properties.
  5130. A cursor property has a current value which can be
  5131. retrieved using the value() function, and set using the setValue()
  5132. slot. In addition, QtCursorPropertyManager provides the
  5133. valueChanged() signal which is emitted whenever a property created
  5134. by this manager changes.
  5135. \sa QtAbstractPropertyManager
  5136. */
  5137. /*!
  5138. \fn void QtCursorPropertyManager::valueChanged(QtProperty *property, const QCursor &value)
  5139. This signal is emitted whenever a property created by this manager
  5140. changes its value, passing a pointer to the \a property and the new
  5141. \a value as parameters.
  5142. \sa setValue()
  5143. */
  5144. /*!
  5145. Creates a manager with the given \a parent.
  5146. */
  5147. QtCursorPropertyManager::QtCursorPropertyManager(QObject *parent)
  5148. : QtAbstractPropertyManager(parent), d_ptr(new QtCursorPropertyManagerPrivate)
  5149. {
  5150. d_ptr->q_ptr = this;
  5151. }
  5152. /*!
  5153. Destroys this manager, and all the properties it has created.
  5154. */
  5155. QtCursorPropertyManager::~QtCursorPropertyManager()
  5156. {
  5157. clear();
  5158. }
  5159. /*!
  5160. Returns the given \a property's value.
  5161. If the given \a property is not managed by this manager, this
  5162. function returns a default QCursor object.
  5163. \sa setValue()
  5164. */
  5165. #ifndef QT_NO_CURSOR
  5166. QCursor QtCursorPropertyManager::value(const QtProperty *property) const
  5167. {
  5168. return d_ptr->m_values.value(property, QCursor());
  5169. }
  5170. #endif
  5171. /*!
  5172. \reimp
  5173. */
  5174. QString QtCursorPropertyManager::valueText(const QtProperty *property) const
  5175. {
  5176. const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  5177. if (it == d_ptr->m_values.constEnd())
  5178. return QString();
  5179. return cursorDatabase()->cursorToShapeName(it.value());
  5180. }
  5181. /*!
  5182. \reimp
  5183. */
  5184. QIcon QtCursorPropertyManager::valueIcon(const QtProperty *property) const
  5185. {
  5186. const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
  5187. if (it == d_ptr->m_values.constEnd())
  5188. return QIcon();
  5189. return cursorDatabase()->cursorToShapeIcon(it.value());
  5190. }
  5191. /*!
  5192. \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
  5193. Sets the value of the given \a property to \a value.
  5194. \sa value(), valueChanged()
  5195. */
  5196. void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
  5197. {
  5198. #ifndef QT_NO_CURSOR
  5199. const QtCursorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
  5200. if (it == d_ptr->m_values.end())
  5201. return;
  5202. if (it.value().shape() == value.shape() && value.shape() != Qt::BitmapCursor)
  5203. return;
  5204. it.value() = value;
  5205. emit propertyChanged(property);
  5206. emit valueChanged(property, value);
  5207. #endif
  5208. }
  5209. /*!
  5210. \reimp
  5211. */
  5212. void QtCursorPropertyManager::initializeProperty(QtProperty *property)
  5213. {
  5214. #ifndef QT_NO_CURSOR
  5215. d_ptr->m_values[property] = QCursor();
  5216. #endif
  5217. }
  5218. /*!
  5219. \reimp
  5220. */
  5221. void QtCursorPropertyManager::uninitializeProperty(QtProperty *property)
  5222. {
  5223. d_ptr->m_values.remove(property);
  5224. }
  5225. QT_END_NAMESPACE
  5226. #include "moc_qtpropertymanager.cpp"
  5227. #include "qtpropertymanager.moc"