qtpropertymanager.cpp 211 KB

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