1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649 |
- /****************************************************************************
- **
- ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
- ** Contact: http://www.qt-project.org/legal
- **
- ** This file is part of the Qt Solutions component.
- **
- ** $QT_BEGIN_LICENSE:BSD$
- ** You may use this file under the terms of the BSD license as follows:
- **
- ** "Redistribution and use in source and binary forms, with or without
- ** modification, are permitted provided that the following conditions are
- ** met:
- ** * Redistributions of source code must retain the above copyright
- ** notice, this list of conditions and the following disclaimer.
- ** * Redistributions in binary form must reproduce the above copyright
- ** notice, this list of conditions and the following disclaimer in
- ** the documentation and/or other materials provided with the
- ** distribution.
- ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
- ** of its contributors may be used to endorse or promote products derived
- ** from this software without specific prior written permission.
- **
- **
- ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
- #pragma execution_character_set("utf-8")
- #include "qtpropertymanager.h"
- #include "qtpropertybrowserutils_p.h"
- #include <QDateTime>
- #include <QLocale>
- #include <QMap>
- #include <QTimer>
- #include <QIcon>
- #include <QMetaEnum>
- #include <QFontDatabase>
- #include <QStyleOption>
- #include <QStyle>
- #include <QApplication>
- #include <QPainter>
- #include <QLabel>
- #include <QCheckBox>
- #include <QLineEdit>
- #include <limits.h>
- #include <float.h>
- #if defined(Q_CC_MSVC)
- # pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
- #endif
- #if QT_VERSION >= 0x040400
- QT_BEGIN_NAMESPACE
- #endif
- template <class PrivateData, class Value>
- static void setSimpleMinimumData(PrivateData *data, const Value &minVal)
- {
- data->minVal = minVal;
- if (data->maxVal < data->minVal)
- data->maxVal = data->minVal;
- if (data->val < data->minVal)
- data->val = data->minVal;
- }
- template <class PrivateData, class Value>
- static void setSimpleMaximumData(PrivateData *data, const Value &maxVal)
- {
- data->maxVal = maxVal;
- if (data->minVal > data->maxVal)
- data->minVal = data->maxVal;
- if (data->val > data->maxVal)
- data->val = data->maxVal;
- }
- template <class PrivateData, class Value>
- static void setSizeMinimumData(PrivateData *data, const Value &newMinVal)
- {
- data->minVal = newMinVal;
- if (data->maxVal.width() < data->minVal.width())
- data->maxVal.setWidth(data->minVal.width());
- if (data->maxVal.height() < data->minVal.height())
- data->maxVal.setHeight(data->minVal.height());
- if (data->val.width() < data->minVal.width())
- data->val.setWidth(data->minVal.width());
- if (data->val.height() < data->minVal.height())
- data->val.setHeight(data->minVal.height());
- }
- template <class PrivateData, class Value>
- static void setSizeMaximumData(PrivateData *data, const Value &newMaxVal)
- {
- data->maxVal = newMaxVal;
- if (data->minVal.width() > data->maxVal.width())
- data->minVal.setWidth(data->maxVal.width());
- if (data->minVal.height() > data->maxVal.height())
- data->minVal.setHeight(data->maxVal.height());
- if (data->val.width() > data->maxVal.width())
- data->val.setWidth(data->maxVal.width());
- if (data->val.height() > data->maxVal.height())
- data->val.setHeight(data->maxVal.height());
- }
- template <class SizeValue>
- static SizeValue qBoundSize(const SizeValue &minVal, const SizeValue &val, const SizeValue &maxVal)
- {
- SizeValue croppedVal = val;
- if (minVal.width() > val.width())
- croppedVal.setWidth(minVal.width());
- else if (maxVal.width() < val.width())
- croppedVal.setWidth(maxVal.width());
- if (minVal.height() > val.height())
- croppedVal.setHeight(minVal.height());
- else if (maxVal.height() < val.height())
- croppedVal.setHeight(maxVal.height());
- return croppedVal;
- }
- // Match the exact signature of qBound for VS 6.
- QSize qBound(QSize minVal, QSize val, QSize maxVal)
- {
- return qBoundSize(minVal, val, maxVal);
- }
- QSizeF qBound(QSizeF minVal, QSizeF val, QSizeF maxVal)
- {
- return qBoundSize(minVal, val, maxVal);
- }
- namespace {
- namespace {
- template <class Value>
- void orderBorders(Value &minVal, Value &maxVal)
- {
- if (minVal > maxVal)
- qSwap(minVal, maxVal);
- }
- template <class Value>
- static void orderSizeBorders(Value &minVal, Value &maxVal)
- {
- Value fromSize = minVal;
- Value toSize = maxVal;
- if (fromSize.width() > toSize.width()) {
- fromSize.setWidth(maxVal.width());
- toSize.setWidth(minVal.width());
- }
- if (fromSize.height() > toSize.height()) {
- fromSize.setHeight(maxVal.height());
- toSize.setHeight(minVal.height());
- }
- minVal = fromSize;
- maxVal = toSize;
- }
- void orderBorders(QSize &minVal, QSize &maxVal)
- {
- orderSizeBorders(minVal, maxVal);
- }
- void orderBorders(QSizeF &minVal, QSizeF &maxVal)
- {
- orderSizeBorders(minVal, maxVal);
- }
- }
- }
- ////////
- template <class Value, class PrivateData>
- static Value getData(const QMap<const QtProperty *, PrivateData> &propertyMap,
- Value PrivateData::*data,
- const QtProperty *property, const Value &defaultValue = Value())
- {
- typedef QMap<const QtProperty *, PrivateData> PropertyToData;
- typedef typename PropertyToData::const_iterator PropertyToDataConstIterator;
- const PropertyToDataConstIterator it = propertyMap.constFind(property);
- if (it == propertyMap.constEnd())
- return defaultValue;
- return it.value().*data;
- }
- template <class Value, class PrivateData>
- static Value getValue(const QMap<const QtProperty *, PrivateData> &propertyMap,
- const QtProperty *property, const Value &defaultValue = Value())
- {
- return getData<Value>(propertyMap, &PrivateData::val, property, defaultValue);
- }
- template <class Value, class PrivateData>
- static Value getMinimum(const QMap<const QtProperty *, PrivateData> &propertyMap,
- const QtProperty *property, const Value &defaultValue = Value())
- {
- return getData<Value>(propertyMap, &PrivateData::minVal, property, defaultValue);
- }
- template <class Value, class PrivateData>
- static Value getMaximum(const QMap<const QtProperty *, PrivateData> &propertyMap,
- const QtProperty *property, const Value &defaultValue = Value())
- {
- return getData<Value>(propertyMap, &PrivateData::maxVal, property, defaultValue);
- }
- template <class ValueChangeParameter, class Value, class PropertyManager>
- static void setSimpleValue(QMap<const QtProperty *, Value> &propertyMap,
- PropertyManager *manager,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- QtProperty *property, const Value &val)
- {
- typedef QMap<const QtProperty *, Value> PropertyToData;
- typedef typename PropertyToData::iterator PropertyToDataIterator;
- const PropertyToDataIterator it = propertyMap.find(property);
- if (it == propertyMap.end())
- return;
- if (it.value() == val)
- return;
- it.value() = val;
- emit (manager->*propertyChangedSignal)(property);
- emit (manager->*valueChangedSignal)(property, val);
- }
- template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
- static void setValueInRange(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- QtProperty *property, const Value &val,
- void (PropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, ValueChangeParameter))
- {
- typedef typename PropertyManagerPrivate::Data PrivateData;
- typedef QMap<const QtProperty *, PrivateData> PropertyToData;
- typedef typename PropertyToData::iterator PropertyToDataIterator;
- const PropertyToDataIterator it = managerPrivate->m_values.find(property);
- if (it == managerPrivate->m_values.end())
- return;
- PrivateData &data = it.value();
- if (data.val == val)
- return;
- const Value oldVal = data.val;
- data.val = qBound(data.minVal, val, data.maxVal);
- if (data.val == oldVal)
- return;
- if (setSubPropertyValue)
- (managerPrivate->*setSubPropertyValue)(property, data.val);
- emit (manager->*propertyChangedSignal)(property);
- emit (manager->*valueChangedSignal)(property, data.val);
- }
- template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
- static void setBorderValues(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
- QtProperty *property, const Value &minVal, const Value &maxVal,
- void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
- ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
- {
- typedef typename PropertyManagerPrivate::Data PrivateData;
- typedef QMap<const QtProperty *, PrivateData> PropertyToData;
- typedef typename PropertyToData::iterator PropertyToDataIterator;
- const PropertyToDataIterator it = managerPrivate->m_values.find(property);
- if (it == managerPrivate->m_values.end())
- return;
- Value fromVal = minVal;
- Value toVal = maxVal;
- orderBorders(fromVal, toVal);
- PrivateData &data = it.value();
- if (data.minVal == fromVal && data.maxVal == toVal)
- return;
- const Value oldVal = data.val;
- data.setMinimumValue(fromVal);
- data.setMaximumValue(toVal);
- emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
- if (setSubPropertyRange)
- (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
- if (data.val == oldVal)
- return;
- emit (manager->*propertyChangedSignal)(property);
- emit (manager->*valueChangedSignal)(property, data.val);
- }
- template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
- static void setBorderValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
- QtProperty *property,
- Value (PrivateData::*getRangeVal)() const,
- void (PrivateData::*setRangeVal)(ValueChangeParameter), const Value &borderVal,
- void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
- ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
- {
- typedef QMap<const QtProperty *, PrivateData> PropertyToData;
- typedef typename PropertyToData::iterator PropertyToDataIterator;
- const PropertyToDataIterator it = managerPrivate->m_values.find(property);
- if (it == managerPrivate->m_values.end())
- return;
- PrivateData &data = it.value();
- if ((data.*getRangeVal)() == borderVal)
- return;
- const Value oldVal = data.val;
- (data.*setRangeVal)(borderVal);
- emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
- if (setSubPropertyRange)
- (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
- if (data.val == oldVal)
- return;
- emit (manager->*propertyChangedSignal)(property);
- emit (manager->*valueChangedSignal)(property, data.val);
- }
- template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
- static void setMinimumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
- QtProperty *property, const Value &minVal)
- {
- void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
- ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
- setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
- propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
- property, &PropertyManagerPrivate::Data::minimumValue, &PropertyManagerPrivate::Data::setMinimumValue, minVal, setSubPropertyRange);
- }
- template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
- static void setMaximumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
- void (PropertyManager::*propertyChangedSignal)(QtProperty *),
- void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
- void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
- QtProperty *property, const Value &maxVal)
- {
- void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
- ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
- setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
- propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
- property, &PropertyManagerPrivate::Data::maximumValue, &PropertyManagerPrivate::Data::setMaximumValue, maxVal, setSubPropertyRange);
- }
- class QtMetaEnumWrapper : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(QSizePolicy::Policy policy READ policy)
- public:
- QSizePolicy::Policy policy() const { return QSizePolicy::Ignored; }
- private:
- QtMetaEnumWrapper(QObject *parent) : QObject(parent) {}
- };
- class QtMetaEnumProvider
- {
- public:
- QtMetaEnumProvider();
- QStringList policyEnumNames() const { return m_policyEnumNames; }
- QStringList languageEnumNames() const { return m_languageEnumNames; }
- QStringList countryEnumNames(QLocale::Language language) const { return m_countryEnumNames.value(language); }
- QSizePolicy::Policy indexToSizePolicy(int index) const;
- int sizePolicyToIndex(QSizePolicy::Policy policy) const;
- void indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const;
- void localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const;
- private:
- void initLocale();
- QStringList m_policyEnumNames;
- QStringList m_languageEnumNames;
- QMap<QLocale::Language, QStringList> m_countryEnumNames;
- QMap<int, QLocale::Language> m_indexToLanguage;
- QMap<QLocale::Language, int> m_languageToIndex;
- QMap<int, QMap<int, QLocale::Country> > m_indexToCountry;
- QMap<QLocale::Language, QMap<QLocale::Country, int> > m_countryToIndex;
- QMetaEnum m_policyEnum;
- };
- #if QT_VERSION < 0x040300
- static QList<QLocale::Country> countriesForLanguage(QLocale::Language language)
- {
- QList<QLocale::Country> countries;
- QLocale::Country country = QLocale::AnyCountry;
- while (country <= QLocale::LastCountry) {
- QLocale locale(language, country);
- if (locale.language() == language && !countries.contains(locale.country()))
- countries << locale.country();
- country = (QLocale::Country)((uint)country + 1); // ++country
- }
- return countries;
- }
- #endif
- static QList<QLocale::Country> sortCountries(const QList<QLocale::Country> &countries)
- {
- QMultiMap<QString, QLocale::Country> nameToCountry;
- QListIterator<QLocale::Country> itCountry(countries);
- while (itCountry.hasNext()) {
- QLocale::Country country = itCountry.next();
- nameToCountry.insert(QLocale::countryToString(country), country);
- }
- return nameToCountry.values();
- }
- void QtMetaEnumProvider::initLocale()
- {
- QMultiMap<QString, QLocale::Language> nameToLanguage;
- QLocale::Language language = QLocale::C;
- while (language <= QLocale::LastLanguage) {
- QLocale locale(language);
- if (locale.language() == language)
- nameToLanguage.insert(QLocale::languageToString(language), language);
- language = (QLocale::Language)((uint)language + 1); // ++language
- }
- const QLocale system = QLocale::system();
- if (!nameToLanguage.contains(QLocale::languageToString(system.language())))
- nameToLanguage.insert(QLocale::languageToString(system.language()), system.language());
- QList<QLocale::Language> languages = nameToLanguage.values();
- QListIterator<QLocale::Language> itLang(languages);
- while (itLang.hasNext()) {
- QLocale::Language language = itLang.next();
- QList<QLocale::Country> countries;
- #if QT_VERSION < 0x040300
- countries = countriesForLanguage(language);
- #else
- countries = QLocale::countriesForLanguage(language);
- #endif
- if (countries.isEmpty() && language == system.language())
- countries << system.country();
- if (!countries.isEmpty() && !m_languageToIndex.contains(language)) {
- countries = sortCountries(countries);
- int langIdx = m_languageEnumNames.count();
- m_indexToLanguage[langIdx] = language;
- m_languageToIndex[language] = langIdx;
- QStringList countryNames;
- QListIterator<QLocale::Country> it(countries);
- int countryIdx = 0;
- while (it.hasNext()) {
- QLocale::Country country = it.next();
- countryNames << QLocale::countryToString(country);
- m_indexToCountry[langIdx][countryIdx] = country;
- m_countryToIndex[language][country] = countryIdx;
- ++countryIdx;
- }
- m_languageEnumNames << QLocale::languageToString(language);
- m_countryEnumNames[language] = countryNames;
- }
- }
- }
- QtMetaEnumProvider::QtMetaEnumProvider()
- {
- QMetaProperty p;
- p = QtMetaEnumWrapper::staticMetaObject.property(
- QtMetaEnumWrapper::staticMetaObject.propertyOffset() + 0);
- m_policyEnum = p.enumerator();
- const int keyCount = m_policyEnum.keyCount();
- for (int i = 0; i < keyCount; i++)
- m_policyEnumNames << QLatin1String(m_policyEnum.key(i));
- initLocale();
- }
- QSizePolicy::Policy QtMetaEnumProvider::indexToSizePolicy(int index) const
- {
- return static_cast<QSizePolicy::Policy>(m_policyEnum.value(index));
- }
- int QtMetaEnumProvider::sizePolicyToIndex(QSizePolicy::Policy policy) const
- {
- const int keyCount = m_policyEnum.keyCount();
- for (int i = 0; i < keyCount; i++)
- if (indexToSizePolicy(i) == policy)
- return i;
- return -1;
- }
- void QtMetaEnumProvider::indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const
- {
- QLocale::Language l = QLocale::C;
- QLocale::Country c = QLocale::AnyCountry;
- if (m_indexToLanguage.contains(languageIndex)) {
- l = m_indexToLanguage[languageIndex];
- if (m_indexToCountry.contains(languageIndex) && m_indexToCountry[languageIndex].contains(countryIndex))
- c = m_indexToCountry[languageIndex][countryIndex];
- }
- if (language)
- *language = l;
- if (country)
- *country = c;
- }
- void QtMetaEnumProvider::localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const
- {
- int l = -1;
- int c = -1;
- if (m_languageToIndex.contains(language)) {
- l = m_languageToIndex[language];
- if (m_countryToIndex.contains(language) && m_countryToIndex[language].contains(country))
- c = m_countryToIndex[language][country];
- }
- if (languageIndex)
- *languageIndex = l;
- if (countryIndex)
- *countryIndex = c;
- }
- Q_GLOBAL_STATIC(QtMetaEnumProvider, metaEnumProvider)
- // QtGroupPropertyManager
- /*!
- \class QtGroupPropertyManager
- \brief The QtGroupPropertyManager provides and manages group properties.
- This class is intended to provide a grouping element without any value.
- \sa QtAbstractPropertyManager
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtGroupPropertyManager::QtGroupPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtGroupPropertyManager::~QtGroupPropertyManager()
- {
- }
- /*!
- \reimp
- */
- bool QtGroupPropertyManager::hasValue(const QtProperty *property) const
- {
- Q_UNUSED(property)
- return false;
- }
- /*!
- \reimp
- */
- void QtGroupPropertyManager::initializeProperty(QtProperty *property)
- {
- Q_UNUSED(property)
- }
- /*!
- \reimp
- */
- void QtGroupPropertyManager::uninitializeProperty(QtProperty *property)
- {
- Q_UNUSED(property)
- }
- // QtIntPropertyManager
- class QtIntPropertyManagerPrivate
- {
- QtIntPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtIntPropertyManager)
- public:
- struct Data
- {
- Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1), readOnly(false) {}
- int val;
- int minVal;
- int maxVal;
- int singleStep;
- bool readOnly;
- int minimumValue() const { return minVal; }
- int maximumValue() const { return maxVal; }
- void setMinimumValue(int newMinVal) { setSimpleMinimumData(this, newMinVal); }
- void setMaximumValue(int newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*!
- \class QtIntPropertyManager
- \brief The QtIntPropertyManager provides and manages int properties.
- An int property has a current value, and a range specifying the
- valid values. The range is defined by a minimum and a maximum
- value.
- The property's value and range can be retrieved using the value(),
- minimum() and maximum() functions, and can be set using the
- setValue(), setMinimum() and setMaximum() slots. Alternatively,
- the range can be defined in one go using the setRange() slot.
- In addition, QtIntPropertyManager provides the valueChanged() signal which
- is emitted whenever a property created by this manager changes,
- and the rangeChanged() signal which is emitted whenever such a
- property changes its range of valid values.
- \sa QtAbstractPropertyManager, QtSpinBoxFactory, QtSliderFactory, QtScrollBarFactory
- */
- /*!
- \fn void QtIntPropertyManager::valueChanged(QtProperty *property, int value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtIntPropertyManager::rangeChanged(QtProperty *property, int minimum, int maximum)
- This signal is emitted whenever a property created by this manager
- changes its range of valid values, passing a pointer to the
- \a property and the new \a minimum and \a maximum values.
- \sa setRange()
- */
- /*!
- \fn void QtIntPropertyManager::singleStepChanged(QtProperty *property, int step)
- This signal is emitted whenever a property created by this manager
- changes its single step property, passing a pointer to the
- \a property and the new \a step value
- \sa setSingleStep()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtIntPropertyManager::QtIntPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtIntPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtIntPropertyManager::~QtIntPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns 0.
- \sa setValue()
- */
- int QtIntPropertyManager::value(const QtProperty *property) const
- {
- return getValue<int>(d_ptr->m_values, property, 0);
- }
- /*!
- Returns the given \a property's minimum value.
- \sa setMinimum(), maximum(), setRange()
- */
- int QtIntPropertyManager::minimum(const QtProperty *property) const
- {
- return getMinimum<int>(d_ptr->m_values, property, 0);
- }
- /*!
- Returns the given \a property's maximum value.
- \sa setMaximum(), minimum(), setRange()
- */
- int QtIntPropertyManager::maximum(const QtProperty *property) const
- {
- return getMaximum<int>(d_ptr->m_values, property, 0);
- }
- /*!
- Returns the given \a property's step value.
- The step is typically used to increment or decrement a property value while pressing an arrow key.
- \sa setSingleStep()
- */
- int QtIntPropertyManager::singleStep(const QtProperty *property) const
- {
- return getData<int>(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::singleStep, property, 0);
- }
- /*!
- Returns read-only status of the property.
- When property is read-only it's value can be selected and copied from editor but not modified.
- \sa QtIntPropertyManager::setReadOnly
- */
- bool QtIntPropertyManager::isReadOnly(const QtProperty *property) const
- {
- return getData<bool>(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::readOnly, property, false);
- }
- /*!
- \reimp
- */
- QString QtIntPropertyManager::valueText(const QtProperty *property) const
- {
- const QtIntPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return QString::number(it.value().val);
- }
- /*!
- \fn void QtIntPropertyManager::setValue(QtProperty *property, int value)
- Sets the value of the given \a property to \a value.
- If the specified \a value is not valid according to the given \a
- property's range, the \a value is adjusted to the nearest valid
- value within the range.
- \sa value(), setRange(), valueChanged()
- */
- void QtIntPropertyManager::setValue(QtProperty *property, int val)
- {
- void (QtIntPropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, int) = 0;
- setValueInRange<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr,
- &QtIntPropertyManager::propertyChanged,
- &QtIntPropertyManager::valueChanged,
- property, val, setSubPropertyValue);
- }
- /*!
- Sets the minimum value for the given \a property to \a minVal.
- When setting the minimum value, the maximum and current values are
- adjusted if necessary (ensuring that the range remains valid and
- that the current value is within the range).
- \sa minimum(), setRange(), rangeChanged()
- */
- void QtIntPropertyManager::setMinimum(QtProperty *property, int minVal)
- {
- setMinimumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr,
- &QtIntPropertyManager::propertyChanged,
- &QtIntPropertyManager::valueChanged,
- &QtIntPropertyManager::rangeChanged,
- property, minVal);
- }
- /*!
- Sets the maximum value for the given \a property to \a maxVal.
- When setting maximum value, the minimum and current values are
- adjusted if necessary (ensuring that the range remains valid and
- that the current value is within the range).
- \sa maximum(), setRange(), rangeChanged()
- */
- void QtIntPropertyManager::setMaximum(QtProperty *property, int maxVal)
- {
- setMaximumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr,
- &QtIntPropertyManager::propertyChanged,
- &QtIntPropertyManager::valueChanged,
- &QtIntPropertyManager::rangeChanged,
- property, maxVal);
- }
- /*!
- \fn void QtIntPropertyManager::setRange(QtProperty *property, int minimum, int maximum)
- Sets the range of valid values.
- This is a convenience function defining the range of valid values
- in one go; setting the \a minimum and \a maximum values for the
- given \a property with a single function call.
- When setting a new range, the current value is adjusted if
- necessary (ensuring that the value remains within range).
- \sa setMinimum(), setMaximum(), rangeChanged()
- */
- void QtIntPropertyManager::setRange(QtProperty *property, int minVal, int maxVal)
- {
- void (QtIntPropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, int, int, int) = 0;
- setBorderValues<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr,
- &QtIntPropertyManager::propertyChanged,
- &QtIntPropertyManager::valueChanged,
- &QtIntPropertyManager::rangeChanged,
- property, minVal, maxVal, setSubPropertyRange);
- }
- /*!
- Sets the step value for the given \a property to \a step.
- The step is typically used to increment or decrement a property value while pressing an arrow key.
- \sa singleStep()
- */
- void QtIntPropertyManager::setSingleStep(QtProperty *property, int step)
- {
- const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtIntPropertyManagerPrivate::Data data = it.value();
- if (step < 0)
- step = 0;
- if (data.singleStep == step)
- return;
- data.singleStep = step;
- it.value() = data;
- emit singleStepChanged(property, data.singleStep);
- }
- /*!
- Sets read-only status of the property.
- \sa QtIntPropertyManager::setReadOnly
- */
- void QtIntPropertyManager::setReadOnly(QtProperty *property, bool readOnly)
- {
- const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtIntPropertyManagerPrivate::Data data = it.value();
- if (data.readOnly == readOnly)
- return;
- data.readOnly = readOnly;
- it.value() = data;
- emit propertyChanged(property);
- emit readOnlyChanged(property, data.readOnly);
- }
- /*!
- \reimp
- */
- void QtIntPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtIntPropertyManagerPrivate::Data();
- }
- /*!
- \reimp
- */
- void QtIntPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtDoublePropertyManager
- class QtDoublePropertyManagerPrivate
- {
- QtDoublePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtDoublePropertyManager)
- public:
- struct Data
- {
- Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1), decimals(2), readOnly(false) {}
- double val;
- double minVal;
- double maxVal;
- double singleStep;
- int decimals;
- bool readOnly;
- double minimumValue() const { return minVal; }
- double maximumValue() const { return maxVal; }
- void setMinimumValue(double newMinVal) { setSimpleMinimumData(this, newMinVal); }
- void setMaximumValue(double newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*!
- \class QtDoublePropertyManager
- \brief The QtDoublePropertyManager provides and manages double properties.
- A double property has a current value, and a range specifying the
- valid values. The range is defined by a minimum and a maximum
- value.
- The property's value and range can be retrieved using the value(),
- minimum() and maximum() functions, and can be set using the
- setValue(), setMinimum() and setMaximum() slots.
- Alternatively, the range can be defined in one go using the
- setRange() slot.
- In addition, QtDoublePropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the rangeChanged() signal which is emitted whenever
- such a property changes its range of valid values.
- \sa QtAbstractPropertyManager, QtDoubleSpinBoxFactory
- */
- /*!
- \fn void QtDoublePropertyManager::valueChanged(QtProperty *property, double value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtDoublePropertyManager::rangeChanged(QtProperty *property, double minimum, double maximum)
- This signal is emitted whenever a property created by this manager
- changes its range of valid values, passing a pointer to the
- \a property and the new \a minimum and \a maximum values
- \sa setRange()
- */
- /*!
- \fn void QtDoublePropertyManager::decimalsChanged(QtProperty *property, int prec)
- This signal is emitted whenever a property created by this manager
- changes its precision of value, passing a pointer to the
- \a property and the new \a prec value
- \sa setDecimals()
- */
- /*!
- \fn void QtDoublePropertyManager::singleStepChanged(QtProperty *property, double step)
- This signal is emitted whenever a property created by this manager
- changes its single step property, passing a pointer to the
- \a property and the new \a step value
- \sa setSingleStep()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtDoublePropertyManager::QtDoublePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtDoublePropertyManagerPrivate;
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtDoublePropertyManager::~QtDoublePropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns 0.
- \sa setValue()
- */
- double QtDoublePropertyManager::value(const QtProperty *property) const
- {
- return getValue<double>(d_ptr->m_values, property, 0.0);
- }
- /*!
- Returns the given \a property's minimum value.
- \sa maximum(), setRange()
- */
- double QtDoublePropertyManager::minimum(const QtProperty *property) const
- {
- return getMinimum<double>(d_ptr->m_values, property, 0.0);
- }
- /*!
- Returns the given \a property's maximum value.
- \sa minimum(), setRange()
- */
- double QtDoublePropertyManager::maximum(const QtProperty *property) const
- {
- return getMaximum<double>(d_ptr->m_values, property, 0.0);
- }
- /*!
- Returns the given \a property's step value.
- The step is typically used to increment or decrement a property value while pressing an arrow key.
- \sa setSingleStep()
- */
- double QtDoublePropertyManager::singleStep(const QtProperty *property) const
- {
- return getData<double>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::singleStep, property, 0);
- }
- /*!
- Returns the given \a property's precision, in decimals.
- \sa setDecimals()
- */
- int QtDoublePropertyManager::decimals(const QtProperty *property) const
- {
- return getData<int>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::decimals, property, 0);
- }
- /*!
- Returns read-only status of the property.
- When property is read-only it's value can be selected and copied from editor but not modified.
- \sa QtDoublePropertyManager::setReadOnly
- */
- bool QtDoublePropertyManager::isReadOnly(const QtProperty *property) const
- {
- return getData<bool>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::readOnly, property, false);
- }
- /*!
- \reimp
- */
- QString QtDoublePropertyManager::valueText(const QtProperty *property) const
- {
- const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return QLocale::system().toString(it.value().val, 'f', it.value().decimals);
- }
- /*!
- \fn void QtDoublePropertyManager::setValue(QtProperty *property, double value)
- Sets the value of the given \a property to \a value.
- If the specified \a value is not valid according to the given
- \a property's range, the \a value is adjusted to the nearest valid value
- within the range.
- \sa value(), setRange(), valueChanged()
- */
- void QtDoublePropertyManager::setValue(QtProperty *property, double val)
- {
- void (QtDoublePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, double) = 0;
- setValueInRange<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr,
- &QtDoublePropertyManager::propertyChanged,
- &QtDoublePropertyManager::valueChanged,
- property, val, setSubPropertyValue);
- }
- /*!
- Sets the step value for the given \a property to \a step.
- The step is typically used to increment or decrement a property value while pressing an arrow key.
- \sa singleStep()
- */
- void QtDoublePropertyManager::setSingleStep(QtProperty *property, double step)
- {
- const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtDoublePropertyManagerPrivate::Data data = it.value();
- if (step < 0)
- step = 0;
- if (data.singleStep == step)
- return;
- data.singleStep = step;
- it.value() = data;
- emit singleStepChanged(property, data.singleStep);
- }
- /*!
- Sets read-only status of the property.
- \sa QtDoublePropertyManager::setReadOnly
- */
- void QtDoublePropertyManager::setReadOnly(QtProperty *property, bool readOnly)
- {
- const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtDoublePropertyManagerPrivate::Data data = it.value();
- if (data.readOnly == readOnly)
- return;
- data.readOnly = readOnly;
- it.value() = data;
- emit propertyChanged(property);
- emit readOnlyChanged(property, data.readOnly);
- }
- /*!
- \fn void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
- Sets the precision of the given \a property to \a prec.
- The valid decimal range is 0-13. The default is 2.
- \sa decimals()
- */
- void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
- {
- const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtDoublePropertyManagerPrivate::Data data = it.value();
- if (prec > 13)
- prec = 13;
- else if (prec < 0)
- prec = 0;
- if (data.decimals == prec)
- return;
- data.decimals = prec;
- it.value() = data;
- emit decimalsChanged(property, data.decimals);
- }
- /*!
- Sets the minimum value for the given \a property to \a minVal.
- When setting the minimum value, the maximum and current values are
- adjusted if necessary (ensuring that the range remains valid and
- that the current value is within in the range).
- \sa minimum(), setRange(), rangeChanged()
- */
- void QtDoublePropertyManager::setMinimum(QtProperty *property, double minVal)
- {
- setMinimumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr,
- &QtDoublePropertyManager::propertyChanged,
- &QtDoublePropertyManager::valueChanged,
- &QtDoublePropertyManager::rangeChanged,
- property, minVal);
- }
- /*!
- Sets the maximum value for the given \a property to \a maxVal.
- When setting the maximum value, the minimum and current values are
- adjusted if necessary (ensuring that the range remains valid and
- that the current value is within in the range).
- \sa maximum(), setRange(), rangeChanged()
- */
- void QtDoublePropertyManager::setMaximum(QtProperty *property, double maxVal)
- {
- setMaximumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr,
- &QtDoublePropertyManager::propertyChanged,
- &QtDoublePropertyManager::valueChanged,
- &QtDoublePropertyManager::rangeChanged,
- property, maxVal);
- }
- /*!
- \fn void QtDoublePropertyManager::setRange(QtProperty *property, double minimum, double maximum)
- Sets the range of valid values.
- This is a convenience function defining the range of valid values
- in one go; setting the \a minimum and \a maximum values for the
- given \a property with a single function call.
- When setting a new range, the current value is adjusted if
- necessary (ensuring that the value remains within range).
- \sa setMinimum(), setMaximum(), rangeChanged()
- */
- void QtDoublePropertyManager::setRange(QtProperty *property, double minVal, double maxVal)
- {
- void (QtDoublePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, double, double, double) = 0;
- setBorderValues<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr,
- &QtDoublePropertyManager::propertyChanged,
- &QtDoublePropertyManager::valueChanged,
- &QtDoublePropertyManager::rangeChanged,
- property, minVal, maxVal, setSubPropertyRange);
- }
- /*!
- \reimp
- */
- void QtDoublePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtDoublePropertyManagerPrivate::Data();
- }
- /*!
- \reimp
- */
- void QtDoublePropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtStringPropertyManager
- class QtStringPropertyManagerPrivate
- {
- QtStringPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtStringPropertyManager)
- public:
- struct Data
- {
- Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard),
- echoMode(QLineEdit::Normal), readOnly(false)
- {
- }
- QString val;
- QRegExp regExp;
- int echoMode;
- bool readOnly;
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- QMap<const QtProperty *, Data> m_values;
- };
- /*!
- \class QtStringPropertyManager
- \brief The QtStringPropertyManager provides and manages QString properties.
- A string property's value can be retrieved using the value()
- function, and set using the setValue() slot.
- The current value can be checked against a regular expression. To
- set the regular expression use the setRegExp() slot, use the
- regExp() function to retrieve the currently set expression.
- In addition, QtStringPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the regExpChanged() signal which is emitted whenever
- such a property changes its currently set regular expression.
- \sa QtAbstractPropertyManager, QtLineEditFactory
- */
- /*!
- \fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegExp ®Exp)
- This signal is emitted whenever a property created by this manager
- changes its currenlty set regular expression, passing a pointer to
- the \a property and the new \a regExp as parameters.
- \sa setRegExp()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtStringPropertyManager::QtStringPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtStringPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtStringPropertyManager::~QtStringPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns an empty string.
- \sa setValue()
- */
- QString QtStringPropertyManager::value(const QtProperty *property) const
- {
- return getValue<QString>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's currently set regular expression.
- If the given \a property is not managed by this manager, this
- function returns an empty expression.
- \sa setRegExp()
- */
- QRegExp QtStringPropertyManager::regExp(const QtProperty *property) const
- {
- return getData<QRegExp>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegExp());
- }
- /*!
- \reimp
- */
- EchoMode QtStringPropertyManager::echoMode(const QtProperty *property) const
- {
- return (EchoMode)getData<int>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::echoMode, property, 0);
- }
- /*!
- Returns read-only status of the property.
- When property is read-only it's value can be selected and copied from editor but not modified.
- \sa QtStringPropertyManager::setReadOnly
- */
- bool QtStringPropertyManager::isReadOnly(const QtProperty *property) const
- {
- return getData<bool>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::readOnly, property, false);
- }
- /*!
- \reimp
- */
- QString QtStringPropertyManager::valueText(const QtProperty *property) const
- {
- const QtStringPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return it.value().val;
- }
- /*!
- \reimp
- */
- QString QtStringPropertyManager::displayText(const QtProperty *property) const
- {
- const QtStringPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- QLineEdit edit;
- edit.setEchoMode((EchoMode)it.value().echoMode);
- edit.setText(it.value().val);
- return edit.displayText();
- }
- /*!
- \fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value)
- Sets the value of the given \a property to \a value.
- If the specified \a value doesn't match the given \a property's
- regular expression, this function does nothing.
- \sa value(), setRegExp(), valueChanged()
- */
- void QtStringPropertyManager::setValue(QtProperty *property, const QString &val)
- {
- const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtStringPropertyManagerPrivate::Data data = it.value();
- if (data.val == val)
- return;
- if (data.regExp.isValid() && !data.regExp.exactMatch(val))
- return;
- data.val = val;
- it.value() = data;
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the regular expression of the given \a property to \a regExp.
- \sa regExp(), setValue(), regExpChanged()
- */
- void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegExp ®Exp)
- {
- const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtStringPropertyManagerPrivate::Data data = it.value() ;
- if (data.regExp == regExp)
- return;
- data.regExp = regExp;
- it.value() = data;
- emit regExpChanged(property, data.regExp);
- }
- void QtStringPropertyManager::setEchoMode(QtProperty *property, EchoMode echoMode)
- {
- const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtStringPropertyManagerPrivate::Data data = it.value();
- if (data.echoMode == echoMode)
- return;
- data.echoMode = echoMode;
- it.value() = data;
- emit propertyChanged(property);
- emit echoModeChanged(property, data.echoMode);
- }
- /*!
- Sets read-only status of the property.
- \sa QtStringPropertyManager::setReadOnly
- */
- void QtStringPropertyManager::setReadOnly(QtProperty *property, bool readOnly)
- {
- const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtStringPropertyManagerPrivate::Data data = it.value();
- if (data.readOnly == readOnly)
- return;
- data.readOnly = readOnly;
- it.value() = data;
- emit propertyChanged(property);
- emit echoModeChanged(property, data.echoMode);
- }
- /*!
- \reimp
- */
- void QtStringPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtStringPropertyManagerPrivate::Data();
- }
- /*!
- \reimp
- */
- void QtStringPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtBoolPropertyManager
- // Return an icon containing a check box indicator
- static QIcon drawCheckBox(bool value)
- {
- QStyleOptionButton opt;
- opt.state |= value ? QStyle::State_On : QStyle::State_Off;
- opt.state |= QStyle::State_Enabled;
- const QStyle *style = QApplication::style();
- // Figure out size of an indicator and make sure it is not scaled down in a list view item
- // by making the pixmap as big as a list view icon and centering the indicator in it.
- // (if it is smaller, it can't be helped)
- const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt);
- const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt);
- const int listViewIconSize = indicatorWidth;
- const int pixmapWidth = indicatorWidth;
- const int pixmapHeight = qMax(indicatorHeight, listViewIconSize);
- opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight);
- QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight);
- pixmap.fill(Qt::transparent);
- {
- // Center?
- const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0;
- const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0;
- QPainter painter(&pixmap);
- painter.translate(xoff, yoff);
- style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
- }
- return QIcon(pixmap);
- }
- class QtBoolPropertyManagerPrivate
- {
- QtBoolPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtBoolPropertyManager)
- public:
- QtBoolPropertyManagerPrivate();
- struct Data
- {
- Data() : val(false), textVisible(true) {}
- bool val;
- bool textVisible;
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- const QIcon m_checkedIcon;
- const QIcon m_uncheckedIcon;
- };
- QtBoolPropertyManagerPrivate::QtBoolPropertyManagerPrivate() :
- m_checkedIcon(drawCheckBox(true)),
- m_uncheckedIcon(drawCheckBox(false))
- {
- }
- /*!
- \class QtBoolPropertyManager
- \brief The QtBoolPropertyManager class provides and manages boolean properties.
- The property's value can be retrieved using the value() function,
- and set using the setValue() slot.
- In addition, QtBoolPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager, QtCheckBoxFactory
- */
- /*!
- \fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtBoolPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtBoolPropertyManager::~QtBoolPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by \e this manager, this
- function returns false.
- \sa setValue()
- */
- bool QtBoolPropertyManager::value(const QtProperty *property) const
- {
- return getValue<bool>(d_ptr->m_values, property, false);
- }
- bool QtBoolPropertyManager::textVisible(const QtProperty *property) const
- {
- return getData<bool>(d_ptr->m_values, &QtBoolPropertyManagerPrivate::Data::textVisible, property, false);
- }
- /*!
- \reimp
- */
- QString QtBoolPropertyManager::valueText(const QtProperty *property) const
- {
- const QtBoolPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QtBoolPropertyManagerPrivate::Data &data = it.value();
- if (!data.textVisible)
- return QString();
- static const QString trueText = tr("True");
- static const QString falseText = tr("False");
- return data.val ? trueText : falseText;
- }
- /*!
- \reimp
- */
- QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const
- {
- const QtBoolPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QIcon();
- return it.value().val ? d_ptr->m_checkedIcon : d_ptr->m_uncheckedIcon;
- }
- /*!
- \fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value)
- Sets the value of the given \a property to \a value.
- \sa value()
- */
- void QtBoolPropertyManager::setValue(QtProperty *property, bool val)
- {
- const QtBoolPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtBoolPropertyManagerPrivate::Data data = it.value();
- if (data.val == val)
- return;
- data.val = val;
- it.value() = data;
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- void QtBoolPropertyManager::setTextVisible(QtProperty *property, bool textVisible)
- {
- const QtBoolPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtBoolPropertyManagerPrivate::Data data = it.value();
- if (data.textVisible == textVisible)
- return;
- data.textVisible = textVisible;
- it.value() = data;
- emit propertyChanged(property);
- emit textVisibleChanged(property, data.textVisible);
- }
- /*!
- \reimp
- */
- void QtBoolPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtBoolPropertyManagerPrivate::Data();
- }
- /*!
- \reimp
- */
- void QtBoolPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtDatePropertyManager
- class QtDatePropertyManagerPrivate
- {
- QtDatePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtDatePropertyManager)
- public:
- struct Data
- {
- Data() : val(QDate::currentDate()), minVal(QDate(1752, 9, 14)),
- maxVal(QDate(7999, 12, 31)) {}
- QDate val;
- QDate minVal;
- QDate maxVal;
- QDate minimumValue() const { return minVal; }
- QDate maximumValue() const { return maxVal; }
- void setMinimumValue(const QDate &newMinVal) { setSimpleMinimumData(this, newMinVal); }
- void setMaximumValue(const QDate &newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
- };
- QString m_format;
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- QMap<const QtProperty *, Data> m_values;
- };
- /*!
- \class QtDatePropertyManager
- \brief The QtDatePropertyManager provides and manages QDate properties.
- A date property has a current value, and a range specifying the
- valid dates. The range is defined by a minimum and a maximum
- value.
- The property's values can be retrieved using the minimum(),
- maximum() and value() functions, and can be set using the
- setMinimum(), setMaximum() and setValue() slots. Alternatively,
- the range can be defined in one go using the setRange() slot.
- In addition, QtDatePropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the rangeChanged() signal which is emitted whenever
- such a property changes its range of valid dates.
- \sa QtAbstractPropertyManager, QtDateEditFactory, QtDateTimePropertyManager
- */
- /*!
- \fn void QtDatePropertyManager::valueChanged(QtProperty *property, const QDate &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtDatePropertyManager::rangeChanged(QtProperty *property, const QDate &minimum, const QDate &maximum)
- This signal is emitted whenever a property created by this manager
- changes its range of valid dates, passing a pointer to the \a
- property and the new \a minimum and \a maximum dates.
- \sa setRange()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtDatePropertyManager::QtDatePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtDatePropertyManagerPrivate;
- d_ptr->q_ptr = this;
- QLocale loc;
- d_ptr->m_format = loc.dateFormat(QLocale::ShortFormat);
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtDatePropertyManager::~QtDatePropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by \e this manager, this
- function returns an invalid date.
- \sa setValue()
- */
- QDate QtDatePropertyManager::value(const QtProperty *property) const
- {
- return getValue<QDate>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's minimum date.
- \sa maximum(), setRange()
- */
- QDate QtDatePropertyManager::minimum(const QtProperty *property) const
- {
- return getMinimum<QDate>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's maximum date.
- \sa minimum(), setRange()
- */
- QDate QtDatePropertyManager::maximum(const QtProperty *property) const
- {
- return getMaximum<QDate>(d_ptr->m_values, property);
- }
- /*!
- \reimp
- */
- QString QtDatePropertyManager::valueText(const QtProperty *property) const
- {
- const QtDatePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return it.value().val.toString(d_ptr->m_format);
- }
- /*!
- \fn void QtDatePropertyManager::setValue(QtProperty *property, const QDate &value)
- Sets the value of the given \a property to \a value.
- If the specified \a value is not a valid date according to the
- given \a property's range, the value is adjusted to the nearest
- valid value within the range.
- \sa value(), setRange(), valueChanged()
- */
- void QtDatePropertyManager::setValue(QtProperty *property, const QDate &val)
- {
- void (QtDatePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, const QDate &) = 0;
- setValueInRange<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, const QDate>(this, d_ptr,
- &QtDatePropertyManager::propertyChanged,
- &QtDatePropertyManager::valueChanged,
- property, val, setSubPropertyValue);
- }
- /*!
- Sets the minimum value for the given \a property to \a minVal.
- When setting the minimum value, the maximum and current values are
- adjusted if necessary (ensuring that the range remains valid and
- that the current value is within in the range).
- \sa minimum(), setRange()
- */
- void QtDatePropertyManager::setMinimum(QtProperty *property, const QDate &minVal)
- {
- setMinimumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr,
- &QtDatePropertyManager::propertyChanged,
- &QtDatePropertyManager::valueChanged,
- &QtDatePropertyManager::rangeChanged,
- property, minVal);
- }
- /*!
- Sets the maximum value for the given \a property to \a maxVal.
- When setting the maximum value, the minimum and current
- values are adjusted if necessary (ensuring that the range remains
- valid and that the current value is within in the range).
- \sa maximum(), setRange()
- */
- void QtDatePropertyManager::setMaximum(QtProperty *property, const QDate &maxVal)
- {
- setMaximumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr,
- &QtDatePropertyManager::propertyChanged,
- &QtDatePropertyManager::valueChanged,
- &QtDatePropertyManager::rangeChanged,
- property, maxVal);
- }
- /*!
- \fn void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minimum, const QDate &maximum)
- Sets the range of valid dates.
- This is a convenience function defining the range of valid dates
- in one go; setting the \a minimum and \a maximum values for the
- given \a property with a single function call.
- When setting a new date range, the current value is adjusted if
- necessary (ensuring that the value remains in date range).
- \sa setMinimum(), setMaximum(), rangeChanged()
- */
- void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minVal, const QDate &maxVal)
- {
- void (QtDatePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, const QDate &,
- const QDate &, const QDate &) = 0;
- setBorderValues<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate>(this, d_ptr,
- &QtDatePropertyManager::propertyChanged,
- &QtDatePropertyManager::valueChanged,
- &QtDatePropertyManager::rangeChanged,
- property, minVal, maxVal, setSubPropertyRange);
- }
- /*!
- \reimp
- */
- void QtDatePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtDatePropertyManagerPrivate::Data();
- }
- /*!
- \reimp
- */
- void QtDatePropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtTimePropertyManager
- class QtTimePropertyManagerPrivate
- {
- QtTimePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtTimePropertyManager)
- public:
- QString m_format;
- typedef QMap<const QtProperty *, QTime> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*!
- \class QtTimePropertyManager
- \brief The QtTimePropertyManager provides and manages QTime properties.
- A time property's value can be retrieved using the value()
- function, and set using the setValue() slot.
- In addition, QtTimePropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager, QtTimeEditFactory
- */
- /*!
- \fn void QtTimePropertyManager::valueChanged(QtProperty *property, const QTime &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtTimePropertyManager::QtTimePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtTimePropertyManagerPrivate;
- d_ptr->q_ptr = this;
- QLocale loc;
- d_ptr->m_format = loc.timeFormat(QLocale::ShortFormat);
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtTimePropertyManager::~QtTimePropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns an invalid time object.
- \sa setValue()
- */
- QTime QtTimePropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QTime());
- }
- /*!
- \reimp
- */
- QString QtTimePropertyManager::valueText(const QtProperty *property) const
- {
- const QtTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return it.value().toString(d_ptr->m_format);
- }
- /*!
- \fn void QtTimePropertyManager::setValue(QtProperty *property, const QTime &value)
- Sets the value of the given \a property to \a value.
- \sa value(), valueChanged()
- */
- void QtTimePropertyManager::setValue(QtProperty *property, const QTime &val)
- {
- setSimpleValue<const QTime &, QTime, QtTimePropertyManager>(d_ptr->m_values, this,
- &QtTimePropertyManager::propertyChanged,
- &QtTimePropertyManager::valueChanged,
- property, val);
- }
- /*!
- \reimp
- */
- void QtTimePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QTime::currentTime();
- }
- /*!
- \reimp
- */
- void QtTimePropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtDateTimePropertyManager
- class QtDateTimePropertyManagerPrivate
- {
- QtDateTimePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtDateTimePropertyManager)
- public:
- QString m_format;
- typedef QMap<const QtProperty *, QDateTime> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*! \class QtDateTimePropertyManager
- \brief The QtDateTimePropertyManager provides and manages QDateTime properties.
- A date and time property has a current value which can be
- retrieved using the value() function, and set using the setValue()
- slot. In addition, QtDateTimePropertyManager provides the
- valueChanged() signal which is emitted whenever a property created
- by this manager changes.
- \sa QtAbstractPropertyManager, QtDateTimeEditFactory, QtDatePropertyManager
- */
- /*!
- \fn void QtDateTimePropertyManager::valueChanged(QtProperty *property, const QDateTime &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtDateTimePropertyManagerPrivate;
- d_ptr->q_ptr = this;
- QLocale loc;
- d_ptr->m_format = loc.dateFormat(QLocale::ShortFormat);
- d_ptr->m_format += QLatin1Char(' ');
- d_ptr->m_format += loc.timeFormat(QLocale::ShortFormat);
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtDateTimePropertyManager::~QtDateTimePropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an invalid QDateTime object.
- \sa setValue()
- */
- QDateTime QtDateTimePropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QDateTime());
- }
- /*!
- \reimp
- */
- QString QtDateTimePropertyManager::valueText(const QtProperty *property) const
- {
- const QtDateTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return it.value().toString(d_ptr->m_format);
- }
- /*!
- \fn void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &value)
- Sets the value of the given \a property to \a value.
- \sa value(), valueChanged()
- */
- void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &val)
- {
- setSimpleValue<const QDateTime &, QDateTime, QtDateTimePropertyManager>(d_ptr->m_values, this,
- &QtDateTimePropertyManager::propertyChanged,
- &QtDateTimePropertyManager::valueChanged,
- property, val);
- }
- /*!
- \reimp
- */
- void QtDateTimePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QDateTime::currentDateTime();
- }
- /*!
- \reimp
- */
- void QtDateTimePropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtKeySequencePropertyManager
- class QtKeySequencePropertyManagerPrivate
- {
- QtKeySequencePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtKeySequencePropertyManager)
- public:
- QString m_format;
- typedef QMap<const QtProperty *, QKeySequence> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*! \class QtKeySequencePropertyManager
- \brief The QtKeySequencePropertyManager provides and manages QKeySequence properties.
- A key sequence's value can be retrieved using the value()
- function, and set using the setValue() slot.
- In addition, QtKeySequencePropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager
- */
- /*!
- \fn void QtKeySequencePropertyManager::valueChanged(QtProperty *property, const QKeySequence &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtKeySequencePropertyManagerPrivate;
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtKeySequencePropertyManager::~QtKeySequencePropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an empty QKeySequence object.
- \sa setValue()
- */
- QKeySequence QtKeySequencePropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QKeySequence());
- }
- /*!
- \reimp
- */
- QString QtKeySequencePropertyManager::valueText(const QtProperty *property) const
- {
- const QtKeySequencePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return it.value().toString(QKeySequence::NativeText);
- }
- /*!
- \fn void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &value)
- Sets the value of the given \a property to \a value.
- \sa value(), valueChanged()
- */
- void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &val)
- {
- setSimpleValue<const QKeySequence &, QKeySequence, QtKeySequencePropertyManager>(d_ptr->m_values, this,
- &QtKeySequencePropertyManager::propertyChanged,
- &QtKeySequencePropertyManager::valueChanged,
- property, val);
- }
- /*!
- \reimp
- */
- void QtKeySequencePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QKeySequence();
- }
- /*!
- \reimp
- */
- void QtKeySequencePropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtCharPropertyManager
- class QtCharPropertyManagerPrivate
- {
- QtCharPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtCharPropertyManager)
- public:
- typedef QMap<const QtProperty *, QChar> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*! \class QtCharPropertyManager
- \brief The QtCharPropertyManager provides and manages QChar properties.
- A char's value can be retrieved using the value()
- function, and set using the setValue() slot.
- In addition, QtCharPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager
- */
- /*!
- \fn void QtCharPropertyManager::valueChanged(QtProperty *property, const QChar &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtCharPropertyManager::QtCharPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtCharPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtCharPropertyManager::~QtCharPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an null QChar object.
- \sa setValue()
- */
- QChar QtCharPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QChar());
- }
- /*!
- \reimp
- */
- QString QtCharPropertyManager::valueText(const QtProperty *property) const
- {
- const QtCharPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QChar c = it.value();
- return c.isNull() ? QString() : QString(c);
- }
- /*!
- \fn void QtCharPropertyManager::setValue(QtProperty *property, const QChar &value)
- Sets the value of the given \a property to \a value.
- \sa value(), valueChanged()
- */
- void QtCharPropertyManager::setValue(QtProperty *property, const QChar &val)
- {
- setSimpleValue<const QChar &, QChar, QtCharPropertyManager>(d_ptr->m_values, this,
- &QtCharPropertyManager::propertyChanged,
- &QtCharPropertyManager::valueChanged,
- property, val);
- }
- /*!
- \reimp
- */
- void QtCharPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QChar();
- }
- /*!
- \reimp
- */
- void QtCharPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtLocalePropertyManager
- class QtLocalePropertyManagerPrivate
- {
- QtLocalePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtLocalePropertyManager)
- public:
- QtLocalePropertyManagerPrivate();
- void slotEnumChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- typedef QMap<const QtProperty *, QLocale> PropertyValueMap;
- PropertyValueMap m_values;
- QtEnumPropertyManager *m_enumPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToLanguage;
- QMap<const QtProperty *, QtProperty *> m_propertyToCountry;
- QMap<const QtProperty *, QtProperty *> m_languageToProperty;
- QMap<const QtProperty *, QtProperty *> m_countryToProperty;
- };
- QtLocalePropertyManagerPrivate::QtLocalePropertyManagerPrivate()
- {
- }
- void QtLocalePropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_languageToProperty.value(property, 0)) {
- const QLocale loc = m_values[prop];
- QLocale::Language newLanguage = loc.language();
- QLocale::Country newCountry = loc.country();
- metaEnumProvider()->indexToLocale(value, 0, &newLanguage, 0);
- QLocale newLoc(newLanguage, newCountry);
- q_ptr->setValue(prop, newLoc);
- } else if (QtProperty *prop = m_countryToProperty.value(property, 0)) {
- const QLocale loc = m_values[prop];
- QLocale::Language newLanguage = loc.language();
- QLocale::Country newCountry = loc.country();
- metaEnumProvider()->indexToLocale(m_enumPropertyManager->value(m_propertyToLanguage.value(prop)), value, &newLanguage, &newCountry);
- QLocale newLoc(newLanguage, newCountry);
- q_ptr->setValue(prop, newLoc);
- }
- }
- void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *subProp = m_languageToProperty.value(property, 0)) {
- m_propertyToLanguage[subProp] = 0;
- m_languageToProperty.remove(property);
- } else if (QtProperty *subProp = m_countryToProperty.value(property, 0)) {
- m_propertyToCountry[subProp] = 0;
- m_countryToProperty.remove(property);
- }
- }
- /*!
- \class QtLocalePropertyManager
- \brief The QtLocalePropertyManager provides and manages QLocale properties.
- A locale property has nested \e language and \e country
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by QtEnumPropertyManager object.
- These submanager can be retrieved using the subEnumPropertyManager()
- function. In order to provide editing widgets for the subproperties
- in a property browser widget, this manager must be associated with editor factory.
- In addition, QtLocalePropertyManager provides the valueChanged()
- signal which is emitted whenever a property created by this
- manager changes.
- \sa QtAbstractPropertyManager, QtEnumPropertyManager
- */
- /*!
- \fn void QtLocalePropertyManager::valueChanged(QtProperty *property, const QLocale &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtLocalePropertyManagerPrivate;
- d_ptr->q_ptr = this;
- d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
- connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotEnumChanged(QtProperty *, int)));
- connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtLocalePropertyManager::~QtLocalePropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the manager that creates the nested \e language
- and \e country subproperties.
- In order to provide editing widgets for the mentioned subproperties
- in a property browser widget, this manager must be associated with
- an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtEnumPropertyManager *QtLocalePropertyManager::subEnumPropertyManager() const
- {
- return d_ptr->m_enumPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns the default locale.
- \sa setValue()
- */
- QLocale QtLocalePropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QLocale());
- }
- /*!
- \reimp
- */
- QString QtLocalePropertyManager::valueText(const QtProperty *property) const
- {
- const QtLocalePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- QLocale loc = it.value();
- int langIdx = 0;
- int countryIdx = 0;
- metaEnumProvider()->localeToIndex(loc.language(), loc.country(), &langIdx, &countryIdx);
- QString str = tr("%1, %2")
- .arg(metaEnumProvider()->languageEnumNames().at(langIdx))
- .arg(metaEnumProvider()->countryEnumNames(loc.language()).at(countryIdx));
- return str;
- }
- /*!
- \fn void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &val)
- {
- const QtLocalePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- const QLocale loc = it.value();
- if (loc == val)
- return;
- it.value() = val;
- int langIdx = 0;
- int countryIdx = 0;
- metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
- if (loc.language() != val.language()) {
- d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToLanguage.value(property), langIdx);
- d_ptr->m_enumPropertyManager->setEnumNames(d_ptr->m_propertyToCountry.value(property),
- metaEnumProvider()->countryEnumNames(val.language()));
- }
- d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToCountry.value(property), countryIdx);
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \reimp
- */
- void QtLocalePropertyManager::initializeProperty(QtProperty *property)
- {
- QLocale val;
- d_ptr->m_values[property] = val;
- int langIdx = 0;
- int countryIdx = 0;
- metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
- QtProperty *languageProp = d_ptr->m_enumPropertyManager->addProperty();
- languageProp->setPropertyName(tr("Language"));
- d_ptr->m_enumPropertyManager->setEnumNames(languageProp, metaEnumProvider()->languageEnumNames());
- d_ptr->m_enumPropertyManager->setValue(languageProp, langIdx);
- d_ptr->m_propertyToLanguage[property] = languageProp;
- d_ptr->m_languageToProperty[languageProp] = property;
- property->addSubProperty(languageProp);
- QtProperty *countryProp = d_ptr->m_enumPropertyManager->addProperty();
- countryProp->setPropertyName(tr("Country"));
- d_ptr->m_enumPropertyManager->setEnumNames(countryProp, metaEnumProvider()->countryEnumNames(val.language()));
- d_ptr->m_enumPropertyManager->setValue(countryProp, countryIdx);
- d_ptr->m_propertyToCountry[property] = countryProp;
- d_ptr->m_countryToProperty[countryProp] = property;
- property->addSubProperty(countryProp);
- }
- /*!
- \reimp
- */
- void QtLocalePropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *languageProp = d_ptr->m_propertyToLanguage[property];
- if (languageProp) {
- d_ptr->m_languageToProperty.remove(languageProp);
- delete languageProp;
- }
- d_ptr->m_propertyToLanguage.remove(property);
- QtProperty *countryProp = d_ptr->m_propertyToCountry[property];
- if (countryProp) {
- d_ptr->m_countryToProperty.remove(countryProp);
- delete countryProp;
- }
- d_ptr->m_propertyToCountry.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtPointPropertyManager
- class QtPointPropertyManagerPrivate
- {
- QtPointPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtPointPropertyManager)
- public:
- void slotIntChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- typedef QMap<const QtProperty *, QPoint> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToX;
- QMap<const QtProperty *, QtProperty *> m_propertyToY;
- QMap<const QtProperty *, QtProperty *> m_xToProperty;
- QMap<const QtProperty *, QtProperty *> m_yToProperty;
- };
- void QtPointPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (QtProperty *xprop = m_xToProperty.value(property, 0)) {
- QPoint p = m_values[xprop];
- p.setX(value);
- q_ptr->setValue(xprop, p);
- } else if (QtProperty *yprop = m_yToProperty.value(property, 0)) {
- QPoint p = m_values[yprop];
- p.setY(value);
- q_ptr->setValue(yprop, p);
- }
- }
- void QtPointPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
- m_propertyToX[pointProp] = 0;
- m_xToProperty.remove(property);
- } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
- m_propertyToY[pointProp] = 0;
- m_yToProperty.remove(property);
- }
- }
- /*! \class QtPointPropertyManager
- \brief The QtPointPropertyManager provides and manages QPoint properties.
- A point property has nested \e x and \e y subproperties. The
- top-level property's value can be retrieved using the value()
- function, and set using the setValue() slot.
- The subproperties are created by a QtIntPropertyManager object. This
- manager can be retrieved using the subIntPropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- In addition, QtPointPropertyManager provides the valueChanged() signal which
- is emitted whenever a property created by this manager changes.
- \sa QtAbstractPropertyManager, QtIntPropertyManager, QtPointFPropertyManager
- */
- /*!
- \fn void QtPointPropertyManager::valueChanged(QtProperty *property, const QPoint &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtPointPropertyManager::QtPointPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtPointPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotIntChanged(QtProperty *, int)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtPointPropertyManager::~QtPointPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the manager that creates the nested \e x and \e y
- subproperties.
- In order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtPointPropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns a point with coordinates (0, 0).
- \sa setValue()
- */
- QPoint QtPointPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QPoint());
- }
- /*!
- \reimp
- */
- QString QtPointPropertyManager::valueText(const QtProperty *property) const
- {
- const QtPointPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QPoint v = it.value();
- return QString(tr("(%1, %2)").arg(QString::number(v.x()))
- .arg(QString::number(v.y())));
- }
- /*!
- \fn void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &val)
- {
- const QtPointPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- if (it.value() == val)
- return;
- it.value() = val;
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \reimp
- */
- void QtPointPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QPoint(0, 0);
- QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
- xProp->setPropertyName(tr("X"));
- d_ptr->m_intPropertyManager->setValue(xProp, 0);
- d_ptr->m_propertyToX[property] = xProp;
- d_ptr->m_xToProperty[xProp] = property;
- property->addSubProperty(xProp);
- QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
- yProp->setPropertyName(tr("Y"));
- d_ptr->m_intPropertyManager->setValue(yProp, 0);
- d_ptr->m_propertyToY[property] = yProp;
- d_ptr->m_yToProperty[yProp] = property;
- property->addSubProperty(yProp);
- }
- /*!
- \reimp
- */
- void QtPointPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *xProp = d_ptr->m_propertyToX[property];
- if (xProp) {
- d_ptr->m_xToProperty.remove(xProp);
- delete xProp;
- }
- d_ptr->m_propertyToX.remove(property);
- QtProperty *yProp = d_ptr->m_propertyToY[property];
- if (yProp) {
- d_ptr->m_yToProperty.remove(yProp);
- delete yProp;
- }
- d_ptr->m_propertyToY.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtPointFPropertyManager
- class QtPointFPropertyManagerPrivate
- {
- QtPointFPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtPointFPropertyManager)
- public:
- struct Data
- {
- Data() : decimals(2) {}
- QPointF val;
- int decimals;
- };
- void slotDoubleChanged(QtProperty *property, double value);
- void slotPropertyDestroyed(QtProperty *property);
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtDoublePropertyManager *m_doublePropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToX;
- QMap<const QtProperty *, QtProperty *> m_propertyToY;
- QMap<const QtProperty *, QtProperty *> m_xToProperty;
- QMap<const QtProperty *, QtProperty *> m_yToProperty;
- };
- void QtPointFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
- {
- if (QtProperty *prop = m_xToProperty.value(property, 0)) {
- QPointF p = m_values[prop].val;
- p.setX(value);
- q_ptr->setValue(prop, p);
- } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
- QPointF p = m_values[prop].val;
- p.setY(value);
- q_ptr->setValue(prop, p);
- }
- }
- void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
- m_propertyToX[pointProp] = 0;
- m_xToProperty.remove(property);
- } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
- m_propertyToY[pointProp] = 0;
- m_yToProperty.remove(property);
- }
- }
- /*! \class QtPointFPropertyManager
- \brief The QtPointFPropertyManager provides and manages QPointF properties.
- A point property has nested \e x and \e y subproperties. The
- top-level property's value can be retrieved using the value()
- function, and set using the setValue() slot.
- The subproperties are created by a QtDoublePropertyManager object. This
- manager can be retrieved using the subDoublePropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- In addition, QtPointFPropertyManager provides the valueChanged() signal which
- is emitted whenever a property created by this manager changes.
- \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtPointPropertyManager
- */
- /*!
- \fn void QtPointFPropertyManager::valueChanged(QtProperty *property, const QPointF &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtPointFPropertyManager::decimalsChanged(QtProperty *property, int prec)
- This signal is emitted whenever a property created by this manager
- changes its precision of value, passing a pointer to the
- \a property and the new \a prec value
- \sa setDecimals()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtPointFPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
- connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)),
- this, SLOT(slotDoubleChanged(QtProperty *, double)));
- connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtPointFPropertyManager::~QtPointFPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the manager that creates the nested \e x and \e y
- subproperties.
- In order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtDoublePropertyManager *QtPointFPropertyManager::subDoublePropertyManager() const
- {
- return d_ptr->m_doublePropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns a point with coordinates (0, 0).
- \sa setValue()
- */
- QPointF QtPointFPropertyManager::value(const QtProperty *property) const
- {
- return getValue<QPointF>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's precision, in decimals.
- \sa setDecimals()
- */
- int QtPointFPropertyManager::decimals(const QtProperty *property) const
- {
- return getData<int>(d_ptr->m_values, &QtPointFPropertyManagerPrivate::Data::decimals, property, 0);
- }
- /*!
- \reimp
- */
- QString QtPointFPropertyManager::valueText(const QtProperty *property) const
- {
- const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QPointF v = it.value().val;
- const int dec = it.value().decimals;
- return QString(tr("(%1, %2)").arg(QString::number(v.x(), 'f', dec))
- .arg(QString::number(v.y(), 'f', dec)));
- }
- /*!
- \fn void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &val)
- {
- const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- if (it.value().val == val)
- return;
- it.value().val = val;
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \fn void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
- Sets the precision of the given \a property to \a prec.
- The valid decimal range is 0-13. The default is 2.
- \sa decimals()
- */
- void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
- {
- const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtPointFPropertyManagerPrivate::Data data = it.value();
- if (prec > 13)
- prec = 13;
- else if (prec < 0)
- prec = 0;
- if (data.decimals == prec)
- return;
- data.decimals = prec;
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
- it.value() = data;
- emit decimalsChanged(property, data.decimals);
- }
- /*!
- \reimp
- */
- void QtPointFPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtPointFPropertyManagerPrivate::Data();
- QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
- xProp->setPropertyName(tr("X"));
- d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(xProp, 0);
- d_ptr->m_propertyToX[property] = xProp;
- d_ptr->m_xToProperty[xProp] = property;
- property->addSubProperty(xProp);
- QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
- yProp->setPropertyName(tr("Y"));
- d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(yProp, 0);
- d_ptr->m_propertyToY[property] = yProp;
- d_ptr->m_yToProperty[yProp] = property;
- property->addSubProperty(yProp);
- }
- /*!
- \reimp
- */
- void QtPointFPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *xProp = d_ptr->m_propertyToX[property];
- if (xProp) {
- d_ptr->m_xToProperty.remove(xProp);
- delete xProp;
- }
- d_ptr->m_propertyToX.remove(property);
- QtProperty *yProp = d_ptr->m_propertyToY[property];
- if (yProp) {
- d_ptr->m_yToProperty.remove(yProp);
- delete yProp;
- }
- d_ptr->m_propertyToY.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtSizePropertyManager
- class QtSizePropertyManagerPrivate
- {
- QtSizePropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtSizePropertyManager)
- public:
- void slotIntChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- void setValue(QtProperty *property, const QSize &val);
- void setRange(QtProperty *property,
- const QSize &minVal, const QSize &maxVal, const QSize &val);
- struct Data
- {
- Data() : val(QSize(0, 0)), minVal(QSize(0, 0)), maxVal(QSize(INT_MAX, INT_MAX)) {}
- QSize val;
- QSize minVal;
- QSize maxVal;
- QSize minimumValue() const { return minVal; }
- QSize maximumValue() const { return maxVal; }
- void setMinimumValue(const QSize &newMinVal) { setSizeMinimumData(this, newMinVal); }
- void setMaximumValue(const QSize &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToW;
- QMap<const QtProperty *, QtProperty *> m_propertyToH;
- QMap<const QtProperty *, QtProperty *> m_wToProperty;
- QMap<const QtProperty *, QtProperty *> m_hToProperty;
- };
- void QtSizePropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_wToProperty.value(property, 0)) {
- QSize s = m_values[prop].val;
- s.setWidth(value);
- q_ptr->setValue(prop, s);
- } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
- QSize s = m_values[prop].val;
- s.setHeight(value);
- q_ptr->setValue(prop, s);
- }
- }
- void QtSizePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
- m_propertyToW[pointProp] = 0;
- m_wToProperty.remove(property);
- } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
- m_propertyToH[pointProp] = 0;
- m_hToProperty.remove(property);
- }
- }
- void QtSizePropertyManagerPrivate::setValue(QtProperty *property, const QSize &val)
- {
- m_intPropertyManager->setValue(m_propertyToW.value(property), val.width());
- m_intPropertyManager->setValue(m_propertyToH.value(property), val.height());
- }
- void QtSizePropertyManagerPrivate::setRange(QtProperty *property,
- const QSize &minVal, const QSize &maxVal, const QSize &val)
- {
- QtProperty *wProperty = m_propertyToW.value(property);
- QtProperty *hProperty = m_propertyToH.value(property);
- m_intPropertyManager->setRange(wProperty, minVal.width(), maxVal.width());
- m_intPropertyManager->setValue(wProperty, val.width());
- m_intPropertyManager->setRange(hProperty, minVal.height(), maxVal.height());
- m_intPropertyManager->setValue(hProperty, val.height());
- }
- /*!
- \class QtSizePropertyManager
- \brief The QtSizePropertyManager provides and manages QSize properties.
- A size property has nested \e width and \e height
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by a QtIntPropertyManager object. This
- manager can be retrieved using the subIntPropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- A size property also has a range of valid values defined by a
- minimum size and a maximum size. These sizes can be retrieved
- using the minimum() and the maximum() functions, and set using the
- setMinimum() and setMaximum() slots. Alternatively, the range can
- be defined in one go using the setRange() slot.
- In addition, QtSizePropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the rangeChanged() signal which is emitted whenever
- such a property changes its range of valid sizes.
- \sa QtAbstractPropertyManager, QtIntPropertyManager, QtSizeFPropertyManager
- */
- /*!
- \fn void QtSizePropertyManager::valueChanged(QtProperty *property, const QSize &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtSizePropertyManager::rangeChanged(QtProperty *property, const QSize &minimum, const QSize &maximum)
- This signal is emitted whenever a property created by this manager
- changes its range of valid sizes, passing a pointer to the \a
- property and the new \a minimum and \a maximum sizes.
- \sa setRange()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtSizePropertyManager::QtSizePropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtSizePropertyManagerPrivate;
- d_ptr->q_ptr = this;
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotIntChanged(QtProperty *, int)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtSizePropertyManager::~QtSizePropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the manager that creates the nested \e width and \e height
- subproperties.
- In order to provide editing widgets for the \e width and \e height
- properties in a property browser widget, this manager must be
- associated with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtSizePropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an invalid size
- \sa setValue()
- */
- QSize QtSizePropertyManager::value(const QtProperty *property) const
- {
- return getValue<QSize>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's minimum size value.
- \sa setMinimum(), maximum(), setRange()
- */
- QSize QtSizePropertyManager::minimum(const QtProperty *property) const
- {
- return getMinimum<QSize>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's maximum size value.
- \sa setMaximum(), minimum(), setRange()
- */
- QSize QtSizePropertyManager::maximum(const QtProperty *property) const
- {
- return getMaximum<QSize>(d_ptr->m_values, property);
- }
- /*!
- \reimp
- */
- QString QtSizePropertyManager::valueText(const QtProperty *property) const
- {
- const QtSizePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QSize v = it.value().val;
- return QString(tr("%1 x %2").arg(QString::number(v.width()))
- .arg(QString::number(v.height())));
- }
- /*!
- \fn void QtSizePropertyManager::setValue(QtProperty *property, const QSize &value)
- Sets the value of the given \a property to \a value.
- If the specified \a value is not valid according to the given \a
- property's size range, the \a value is adjusted to the nearest
- valid value within the size range.
- \sa value(), setRange(), valueChanged()
- */
- void QtSizePropertyManager::setValue(QtProperty *property, const QSize &val)
- {
- setValueInRange<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, const QSize>(this, d_ptr,
- &QtSizePropertyManager::propertyChanged,
- &QtSizePropertyManager::valueChanged,
- property, val, &QtSizePropertyManagerPrivate::setValue);
- }
- /*!
- Sets the minimum size value for the given \a property to \a minVal.
- When setting the minimum size value, the maximum and current
- values are adjusted if necessary (ensuring that the size range
- remains valid and that the current value is within the range).
- \sa minimum(), setRange(), rangeChanged()
- */
- void QtSizePropertyManager::setMinimum(QtProperty *property, const QSize &minVal)
- {
- setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr,
- &QtSizePropertyManager::propertyChanged,
- &QtSizePropertyManager::valueChanged,
- &QtSizePropertyManager::rangeChanged,
- property,
- &QtSizePropertyManagerPrivate::Data::minimumValue,
- &QtSizePropertyManagerPrivate::Data::setMinimumValue,
- minVal, &QtSizePropertyManagerPrivate::setRange);
- }
- /*!
- Sets the maximum size value for the given \a property to \a maxVal.
- When setting the maximum size value, the minimum and current
- values are adjusted if necessary (ensuring that the size range
- remains valid and that the current value is within the range).
- \sa maximum(), setRange(), rangeChanged()
- */
- void QtSizePropertyManager::setMaximum(QtProperty *property, const QSize &maxVal)
- {
- setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr,
- &QtSizePropertyManager::propertyChanged,
- &QtSizePropertyManager::valueChanged,
- &QtSizePropertyManager::rangeChanged,
- property,
- &QtSizePropertyManagerPrivate::Data::maximumValue,
- &QtSizePropertyManagerPrivate::Data::setMaximumValue,
- maxVal, &QtSizePropertyManagerPrivate::setRange);
- }
- /*!
- \fn void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minimum, const QSize &maximum)
- Sets the range of valid values.
- This is a convenience function defining the range of valid values
- in one go; setting the \a minimum and \a maximum values for the
- given \a property with a single function call.
- When setting a new range, the current value is adjusted if
- necessary (ensuring that the value remains within the range).
- \sa setMinimum(), setMaximum(), rangeChanged()
- */
- void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minVal, const QSize &maxVal)
- {
- setBorderValues<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize>(this, d_ptr,
- &QtSizePropertyManager::propertyChanged,
- &QtSizePropertyManager::valueChanged,
- &QtSizePropertyManager::rangeChanged,
- property, minVal, maxVal, &QtSizePropertyManagerPrivate::setRange);
- }
- /*!
- \reimp
- */
- void QtSizePropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtSizePropertyManagerPrivate::Data();
- QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
- wProp->setPropertyName(tr("Width"));
- d_ptr->m_intPropertyManager->setValue(wProp, 0);
- d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
- d_ptr->m_propertyToW[property] = wProp;
- d_ptr->m_wToProperty[wProp] = property;
- property->addSubProperty(wProp);
- QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
- hProp->setPropertyName(tr("Height"));
- d_ptr->m_intPropertyManager->setValue(hProp, 0);
- d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
- d_ptr->m_propertyToH[property] = hProp;
- d_ptr->m_hToProperty[hProp] = property;
- property->addSubProperty(hProp);
- }
- /*!
- \reimp
- */
- void QtSizePropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *wProp = d_ptr->m_propertyToW[property];
- if (wProp) {
- d_ptr->m_wToProperty.remove(wProp);
- delete wProp;
- }
- d_ptr->m_propertyToW.remove(property);
- QtProperty *hProp = d_ptr->m_propertyToH[property];
- if (hProp) {
- d_ptr->m_hToProperty.remove(hProp);
- delete hProp;
- }
- d_ptr->m_propertyToH.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtSizeFPropertyManager
- class QtSizeFPropertyManagerPrivate
- {
- QtSizeFPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtSizeFPropertyManager)
- public:
- void slotDoubleChanged(QtProperty *property, double value);
- void slotPropertyDestroyed(QtProperty *property);
- void setValue(QtProperty *property, const QSizeF &val);
- void setRange(QtProperty *property,
- const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val);
- struct Data
- {
- Data() : val(QSizeF(0, 0)), minVal(QSizeF(0, 0)), maxVal(QSizeF(INT_MAX, INT_MAX)), decimals(2) {}
- QSizeF val;
- QSizeF minVal;
- QSizeF maxVal;
- int decimals;
- QSizeF minimumValue() const { return minVal; }
- QSizeF maximumValue() const { return maxVal; }
- void setMinimumValue(const QSizeF &newMinVal) { setSizeMinimumData(this, newMinVal); }
- void setMaximumValue(const QSizeF &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtDoublePropertyManager *m_doublePropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToW;
- QMap<const QtProperty *, QtProperty *> m_propertyToH;
- QMap<const QtProperty *, QtProperty *> m_wToProperty;
- QMap<const QtProperty *, QtProperty *> m_hToProperty;
- };
- void QtSizeFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
- {
- if (QtProperty *prop = m_wToProperty.value(property, 0)) {
- QSizeF s = m_values[prop].val;
- s.setWidth(value);
- q_ptr->setValue(prop, s);
- } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
- QSizeF s = m_values[prop].val;
- s.setHeight(value);
- q_ptr->setValue(prop, s);
- }
- }
- void QtSizeFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
- m_propertyToW[pointProp] = 0;
- m_wToProperty.remove(property);
- } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
- m_propertyToH[pointProp] = 0;
- m_hToProperty.remove(property);
- }
- }
- void QtSizeFPropertyManagerPrivate::setValue(QtProperty *property, const QSizeF &val)
- {
- m_doublePropertyManager->setValue(m_propertyToW.value(property), val.width());
- m_doublePropertyManager->setValue(m_propertyToH.value(property), val.height());
- }
- void QtSizeFPropertyManagerPrivate::setRange(QtProperty *property,
- const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val)
- {
- m_doublePropertyManager->setRange(m_propertyToW[property], minVal.width(), maxVal.width());
- m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
- m_doublePropertyManager->setRange(m_propertyToH[property], minVal.height(), maxVal.height());
- m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
- }
- /*!
- \class QtSizeFPropertyManager
- \brief The QtSizeFPropertyManager provides and manages QSizeF properties.
- A size property has nested \e width and \e height
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by a QtDoublePropertyManager object. This
- manager can be retrieved using the subDoublePropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- A size property also has a range of valid values defined by a
- minimum size and a maximum size. These sizes can be retrieved
- using the minimum() and the maximum() functions, and set using the
- setMinimum() and setMaximum() slots. Alternatively, the range can
- be defined in one go using the setRange() slot.
- In addition, QtSizeFPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the rangeChanged() signal which is emitted whenever
- such a property changes its range of valid sizes.
- \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtSizePropertyManager
- */
- /*!
- \fn void QtSizeFPropertyManager::valueChanged(QtProperty *property, const QSizeF &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtSizeFPropertyManager::rangeChanged(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
- This signal is emitted whenever a property created by this manager
- changes its range of valid sizes, passing a pointer to the \a
- property and the new \a minimum and \a maximum sizes.
- \sa setRange()
- */
- /*!
- \fn void QtSizeFPropertyManager::decimalsChanged(QtProperty *property, int prec)
- This signal is emitted whenever a property created by this manager
- changes its precision of value, passing a pointer to the
- \a property and the new \a prec value
- \sa setDecimals()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtSizeFPropertyManager::QtSizeFPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtSizeFPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
- connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)),
- this, SLOT(slotDoubleChanged(QtProperty *, double)));
- connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtSizeFPropertyManager::~QtSizeFPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the manager that creates the nested \e width and \e height
- subproperties.
- In order to provide editing widgets for the \e width and \e height
- properties in a property browser widget, this manager must be
- associated with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtDoublePropertyManager *QtSizeFPropertyManager::subDoublePropertyManager() const
- {
- return d_ptr->m_doublePropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an invalid size
- \sa setValue()
- */
- QSizeF QtSizeFPropertyManager::value(const QtProperty *property) const
- {
- return getValue<QSizeF>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's precision, in decimals.
- \sa setDecimals()
- */
- int QtSizeFPropertyManager::decimals(const QtProperty *property) const
- {
- return getData<int>(d_ptr->m_values, &QtSizeFPropertyManagerPrivate::Data::decimals, property, 0);
- }
- /*!
- Returns the given \a property's minimum size value.
- \sa setMinimum(), maximum(), setRange()
- */
- QSizeF QtSizeFPropertyManager::minimum(const QtProperty *property) const
- {
- return getMinimum<QSizeF>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's maximum size value.
- \sa setMaximum(), minimum(), setRange()
- */
- QSizeF QtSizeFPropertyManager::maximum(const QtProperty *property) const
- {
- return getMaximum<QSizeF>(d_ptr->m_values, property);
- }
- /*!
- \reimp
- */
- QString QtSizeFPropertyManager::valueText(const QtProperty *property) const
- {
- const QtSizeFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QSizeF v = it.value().val;
- const int dec = it.value().decimals;
- return QString(tr("%1 x %2").arg(QString::number(v.width(), 'f', dec))
- .arg(QString::number(v.height(), 'f', dec)));
- }
- /*!
- \fn void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &value)
- Sets the value of the given \a property to \a value.
- If the specified \a value is not valid according to the given \a
- property's size range, the \a value is adjusted to the nearest
- valid value within the size range.
- \sa value(), setRange(), valueChanged()
- */
- void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &val)
- {
- setValueInRange<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr,
- &QtSizeFPropertyManager::propertyChanged,
- &QtSizeFPropertyManager::valueChanged,
- property, val, &QtSizeFPropertyManagerPrivate::setValue);
- }
- /*!
- \fn void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
- Sets the precision of the given \a property to \a prec.
- The valid decimal range is 0-13. The default is 2.
- \sa decimals()
- */
- void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
- {
- const QtSizeFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtSizeFPropertyManagerPrivate::Data data = it.value();
- if (prec > 13)
- prec = 13;
- else if (prec < 0)
- prec = 0;
- if (data.decimals == prec)
- return;
- data.decimals = prec;
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
- it.value() = data;
- emit decimalsChanged(property, data.decimals);
- }
- /*!
- Sets the minimum size value for the given \a property to \a minVal.
- When setting the minimum size value, the maximum and current
- values are adjusted if necessary (ensuring that the size range
- remains valid and that the current value is within the range).
- \sa minimum(), setRange(), rangeChanged()
- */
- void QtSizeFPropertyManager::setMinimum(QtProperty *property, const QSizeF &minVal)
- {
- setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr,
- &QtSizeFPropertyManager::propertyChanged,
- &QtSizeFPropertyManager::valueChanged,
- &QtSizeFPropertyManager::rangeChanged,
- property,
- &QtSizeFPropertyManagerPrivate::Data::minimumValue,
- &QtSizeFPropertyManagerPrivate::Data::setMinimumValue,
- minVal, &QtSizeFPropertyManagerPrivate::setRange);
- }
- /*!
- Sets the maximum size value for the given \a property to \a maxVal.
- When setting the maximum size value, the minimum and current
- values are adjusted if necessary (ensuring that the size range
- remains valid and that the current value is within the range).
- \sa maximum(), setRange(), rangeChanged()
- */
- void QtSizeFPropertyManager::setMaximum(QtProperty *property, const QSizeF &maxVal)
- {
- setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr,
- &QtSizeFPropertyManager::propertyChanged,
- &QtSizeFPropertyManager::valueChanged,
- &QtSizeFPropertyManager::rangeChanged,
- property,
- &QtSizeFPropertyManagerPrivate::Data::maximumValue,
- &QtSizeFPropertyManagerPrivate::Data::setMaximumValue,
- maxVal, &QtSizeFPropertyManagerPrivate::setRange);
- }
- /*!
- \fn void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
- Sets the range of valid values.
- This is a convenience function defining the range of valid values
- in one go; setting the \a minimum and \a maximum values for the
- given \a property with a single function call.
- When setting a new range, the current value is adjusted if
- necessary (ensuring that the value remains within the range).
- \sa setMinimum(), setMaximum(), rangeChanged()
- */
- void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minVal, const QSizeF &maxVal)
- {
- setBorderValues<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr,
- &QtSizeFPropertyManager::propertyChanged,
- &QtSizeFPropertyManager::valueChanged,
- &QtSizeFPropertyManager::rangeChanged,
- property, minVal, maxVal, &QtSizeFPropertyManagerPrivate::setRange);
- }
- /*!
- \reimp
- */
- void QtSizeFPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtSizeFPropertyManagerPrivate::Data();
- QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
- wProp->setPropertyName(tr("Width"));
- d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(wProp, 0);
- d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
- d_ptr->m_propertyToW[property] = wProp;
- d_ptr->m_wToProperty[wProp] = property;
- property->addSubProperty(wProp);
- QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
- hProp->setPropertyName(tr("Height"));
- d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(hProp, 0);
- d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
- d_ptr->m_propertyToH[property] = hProp;
- d_ptr->m_hToProperty[hProp] = property;
- property->addSubProperty(hProp);
- }
- /*!
- \reimp
- */
- void QtSizeFPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *wProp = d_ptr->m_propertyToW[property];
- if (wProp) {
- d_ptr->m_wToProperty.remove(wProp);
- delete wProp;
- }
- d_ptr->m_propertyToW.remove(property);
- QtProperty *hProp = d_ptr->m_propertyToH[property];
- if (hProp) {
- d_ptr->m_hToProperty.remove(hProp);
- delete hProp;
- }
- d_ptr->m_propertyToH.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtRectPropertyManager
- class QtRectPropertyManagerPrivate
- {
- QtRectPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtRectPropertyManager)
- public:
- void slotIntChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- void setConstraint(QtProperty *property, const QRect &constraint, const QRect &val);
- struct Data
- {
- Data() : val(0, 0, 0, 0) {}
- QRect val;
- QRect constraint;
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToX;
- QMap<const QtProperty *, QtProperty *> m_propertyToY;
- QMap<const QtProperty *, QtProperty *> m_propertyToW;
- QMap<const QtProperty *, QtProperty *> m_propertyToH;
- QMap<const QtProperty *, QtProperty *> m_xToProperty;
- QMap<const QtProperty *, QtProperty *> m_yToProperty;
- QMap<const QtProperty *, QtProperty *> m_wToProperty;
- QMap<const QtProperty *, QtProperty *> m_hToProperty;
- };
- void QtRectPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_xToProperty.value(property, 0)) {
- QRect r = m_values[prop].val;
- r.moveLeft(value);
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_yToProperty.value(property)) {
- QRect r = m_values[prop].val;
- r.moveTop(value);
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
- Data data = m_values[prop];
- QRect r = data.val;
- r.setWidth(value);
- if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
- r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
- }
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
- Data data = m_values[prop];
- QRect r = data.val;
- r.setHeight(value);
- if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
- r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
- }
- q_ptr->setValue(prop, r);
- }
- }
- void QtRectPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
- m_propertyToX[pointProp] = 0;
- m_xToProperty.remove(property);
- } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
- m_propertyToY[pointProp] = 0;
- m_yToProperty.remove(property);
- } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
- m_propertyToW[pointProp] = 0;
- m_wToProperty.remove(property);
- } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
- m_propertyToH[pointProp] = 0;
- m_hToProperty.remove(property);
- }
- }
- void QtRectPropertyManagerPrivate::setConstraint(QtProperty *property,
- const QRect &constraint, const QRect &val)
- {
- const bool isNull = constraint.isNull();
- const int left = isNull ? INT_MIN : constraint.left();
- const int right = isNull ? INT_MAX : constraint.left() + constraint.width();
- const int top = isNull ? INT_MIN : constraint.top();
- const int bottom = isNull ? INT_MAX : constraint.top() + constraint.height();
- const int width = isNull ? INT_MAX : constraint.width();
- const int height = isNull ? INT_MAX : constraint.height();
- m_intPropertyManager->setRange(m_propertyToX[property], left, right);
- m_intPropertyManager->setRange(m_propertyToY[property], top, bottom);
- m_intPropertyManager->setRange(m_propertyToW[property], 0, width);
- m_intPropertyManager->setRange(m_propertyToH[property], 0, height);
- m_intPropertyManager->setValue(m_propertyToX[property], val.x());
- m_intPropertyManager->setValue(m_propertyToY[property], val.y());
- m_intPropertyManager->setValue(m_propertyToW[property], val.width());
- m_intPropertyManager->setValue(m_propertyToH[property], val.height());
- }
- /*!
- \class QtRectPropertyManager
- \brief The QtRectPropertyManager provides and manages QRect properties.
- A rectangle property has nested \e x, \e y, \e width and \e height
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by a QtIntPropertyManager object. This
- manager can be retrieved using the subIntPropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- A rectangle property also has a constraint rectangle which can be
- retrieved using the constraint() function, and set using the
- setConstraint() slot.
- In addition, QtRectPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the constraintChanged() signal which is emitted
- whenever such a property changes its constraint rectangle.
- \sa QtAbstractPropertyManager, QtIntPropertyManager, QtRectFPropertyManager
- */
- /*!
- \fn void QtRectPropertyManager::valueChanged(QtProperty *property, const QRect &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtRectPropertyManager::constraintChanged(QtProperty *property, const QRect &constraint)
- This signal is emitted whenever property changes its constraint
- rectangle, passing a pointer to the \a property and the new \a
- constraint rectangle as parameters.
- \sa setConstraint()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtRectPropertyManager::QtRectPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtRectPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotIntChanged(QtProperty *, int)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtRectPropertyManager::~QtRectPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the manager that creates the nested \e x, \e y, \e width
- and \e height subproperties.
- In order to provide editing widgets for the mentioned
- subproperties in a property browser widget, this manager must be
- associated with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtRectPropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an invalid rectangle.
- \sa setValue(), constraint()
- */
- QRect QtRectPropertyManager::value(const QtProperty *property) const
- {
- return getValue<QRect>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's constraining rectangle. If returned value is null QRect it means there is no constraint applied.
- \sa value(), setConstraint()
- */
- QRect QtRectPropertyManager::constraint(const QtProperty *property) const
- {
- return getData<QRect>(d_ptr->m_values, &QtRectPropertyManagerPrivate::Data::constraint, property, QRect());
- }
- /*!
- \reimp
- */
- QString QtRectPropertyManager::valueText(const QtProperty *property) const
- {
- const QtRectPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QRect v = it.value().val;
- return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x()))
- .arg(QString::number(v.y()))
- .arg(QString::number(v.width()))
- .arg(QString::number(v.height())));
- }
- /*!
- \fn void QtRectPropertyManager::setValue(QtProperty *property, const QRect &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- If the specified \a value is not inside the given \a property's
- constraining rectangle, the value is adjusted accordingly to fit
- within the constraint.
- \sa value(), setConstraint(), valueChanged()
- */
- void QtRectPropertyManager::setValue(QtProperty *property, const QRect &val)
- {
- const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtRectPropertyManagerPrivate::Data data = it.value();
- QRect newRect = val.normalized();
- if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
- const QRect r1 = data.constraint;
- const QRect r2 = newRect;
- newRect.setLeft(qMax(r1.left(), r2.left()));
- newRect.setRight(qMin(r1.right(), r2.right()));
- newRect.setTop(qMax(r1.top(), r2.top()));
- newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
- if (newRect.width() < 0 || newRect.height() < 0)
- return;
- }
- if (data.val == newRect)
- return;
- data.val = newRect;
- it.value() = data;
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the given \a property's constraining rectangle to \a
- constraint.
- When setting the constraint, the current value is adjusted if
- necessary (ensuring that the current rectangle value is inside the
- constraint). In order to reset the constraint pass a null QRect value.
- \sa setValue(), constraint(), constraintChanged()
- */
- void QtRectPropertyManager::setConstraint(QtProperty *property, const QRect &constraint)
- {
- const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtRectPropertyManagerPrivate::Data data = it.value();
- QRect newConstraint = constraint.normalized();
- if (data.constraint == newConstraint)
- return;
- const QRect oldVal = data.val;
- data.constraint = newConstraint;
- if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
- QRect r1 = data.constraint;
- QRect r2 = data.val;
- if (r2.width() > r1.width())
- r2.setWidth(r1.width());
- if (r2.height() > r1.height())
- r2.setHeight(r1.height());
- if (r2.left() < r1.left())
- r2.moveLeft(r1.left());
- else if (r2.right() > r1.right())
- r2.moveRight(r1.right());
- if (r2.top() < r1.top())
- r2.moveTop(r1.top());
- else if (r2.bottom() > r1.bottom())
- r2.moveBottom(r1.bottom());
- data.val = r2;
- }
- it.value() = data;
- emit constraintChanged(property, data.constraint);
- d_ptr->setConstraint(property, data.constraint, data.val);
- if (data.val == oldVal)
- return;
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- \reimp
- */
- void QtRectPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtRectPropertyManagerPrivate::Data();
- QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
- xProp->setPropertyName(tr("X"));
- d_ptr->m_intPropertyManager->setValue(xProp, 0);
- d_ptr->m_propertyToX[property] = xProp;
- d_ptr->m_xToProperty[xProp] = property;
- property->addSubProperty(xProp);
- QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
- yProp->setPropertyName(tr("Y"));
- d_ptr->m_intPropertyManager->setValue(yProp, 0);
- d_ptr->m_propertyToY[property] = yProp;
- d_ptr->m_yToProperty[yProp] = property;
- property->addSubProperty(yProp);
- QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
- wProp->setPropertyName(tr("Width"));
- d_ptr->m_intPropertyManager->setValue(wProp, 0);
- d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
- d_ptr->m_propertyToW[property] = wProp;
- d_ptr->m_wToProperty[wProp] = property;
- property->addSubProperty(wProp);
- QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
- hProp->setPropertyName(tr("Height"));
- d_ptr->m_intPropertyManager->setValue(hProp, 0);
- d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
- d_ptr->m_propertyToH[property] = hProp;
- d_ptr->m_hToProperty[hProp] = property;
- property->addSubProperty(hProp);
- }
- /*!
- \reimp
- */
- void QtRectPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *xProp = d_ptr->m_propertyToX[property];
- if (xProp) {
- d_ptr->m_xToProperty.remove(xProp);
- delete xProp;
- }
- d_ptr->m_propertyToX.remove(property);
- QtProperty *yProp = d_ptr->m_propertyToY[property];
- if (yProp) {
- d_ptr->m_yToProperty.remove(yProp);
- delete yProp;
- }
- d_ptr->m_propertyToY.remove(property);
- QtProperty *wProp = d_ptr->m_propertyToW[property];
- if (wProp) {
- d_ptr->m_wToProperty.remove(wProp);
- delete wProp;
- }
- d_ptr->m_propertyToW.remove(property);
- QtProperty *hProp = d_ptr->m_propertyToH[property];
- if (hProp) {
- d_ptr->m_hToProperty.remove(hProp);
- delete hProp;
- }
- d_ptr->m_propertyToH.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtRectFPropertyManager
- class QtRectFPropertyManagerPrivate
- {
- QtRectFPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtRectFPropertyManager)
- public:
- void slotDoubleChanged(QtProperty *property, double value);
- void slotPropertyDestroyed(QtProperty *property);
- void setConstraint(QtProperty *property, const QRectF &constraint, const QRectF &val);
- struct Data
- {
- Data() : val(0, 0, 0, 0), decimals(2) {}
- QRectF val;
- QRectF constraint;
- int decimals;
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtDoublePropertyManager *m_doublePropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToX;
- QMap<const QtProperty *, QtProperty *> m_propertyToY;
- QMap<const QtProperty *, QtProperty *> m_propertyToW;
- QMap<const QtProperty *, QtProperty *> m_propertyToH;
- QMap<const QtProperty *, QtProperty *> m_xToProperty;
- QMap<const QtProperty *, QtProperty *> m_yToProperty;
- QMap<const QtProperty *, QtProperty *> m_wToProperty;
- QMap<const QtProperty *, QtProperty *> m_hToProperty;
- };
- void QtRectFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
- {
- if (QtProperty *prop = m_xToProperty.value(property, 0)) {
- QRectF r = m_values[prop].val;
- r.moveLeft(value);
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
- QRectF r = m_values[prop].val;
- r.moveTop(value);
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
- Data data = m_values[prop];
- QRectF r = data.val;
- r.setWidth(value);
- if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
- r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
- }
- q_ptr->setValue(prop, r);
- } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
- Data data = m_values[prop];
- QRectF r = data.val;
- r.setHeight(value);
- if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
- r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
- }
- q_ptr->setValue(prop, r);
- }
- }
- void QtRectFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
- m_propertyToX[pointProp] = 0;
- m_xToProperty.remove(property);
- } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
- m_propertyToY[pointProp] = 0;
- m_yToProperty.remove(property);
- } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
- m_propertyToW[pointProp] = 0;
- m_wToProperty.remove(property);
- } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
- m_propertyToH[pointProp] = 0;
- m_hToProperty.remove(property);
- }
- }
- void QtRectFPropertyManagerPrivate::setConstraint(QtProperty *property,
- const QRectF &constraint, const QRectF &val)
- {
- const bool isNull = constraint.isNull();
- const float left = isNull ? FLT_MIN : constraint.left();
- const float right = isNull ? FLT_MAX : constraint.left() + constraint.width();
- const float top = isNull ? FLT_MIN : constraint.top();
- const float bottom = isNull ? FLT_MAX : constraint.top() + constraint.height();
- const float width = isNull ? FLT_MAX : constraint.width();
- const float height = isNull ? FLT_MAX : constraint.height();
- m_doublePropertyManager->setRange(m_propertyToX[property], left, right);
- m_doublePropertyManager->setRange(m_propertyToY[property], top, bottom);
- m_doublePropertyManager->setRange(m_propertyToW[property], 0, width);
- m_doublePropertyManager->setRange(m_propertyToH[property], 0, height);
- m_doublePropertyManager->setValue(m_propertyToX[property], val.x());
- m_doublePropertyManager->setValue(m_propertyToY[property], val.y());
- m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
- m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
- }
- /*!
- \class QtRectFPropertyManager
- \brief The QtRectFPropertyManager provides and manages QRectF properties.
- A rectangle property has nested \e x, \e y, \e width and \e height
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by a QtDoublePropertyManager object. This
- manager can be retrieved using the subDoublePropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- A rectangle property also has a constraint rectangle which can be
- retrieved using the constraint() function, and set using the
- setConstraint() slot.
- In addition, QtRectFPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the constraintChanged() signal which is emitted
- whenever such a property changes its constraint rectangle.
- \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtRectPropertyManager
- */
- /*!
- \fn void QtRectFPropertyManager::valueChanged(QtProperty *property, const QRectF &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtRectFPropertyManager::constraintChanged(QtProperty *property, const QRectF &constraint)
- This signal is emitted whenever property changes its constraint
- rectangle, passing a pointer to the \a property and the new \a
- constraint rectangle as parameters.
- \sa setConstraint()
- */
- /*!
- \fn void QtRectFPropertyManager::decimalsChanged(QtProperty *property, int prec)
- This signal is emitted whenever a property created by this manager
- changes its precision of value, passing a pointer to the
- \a property and the new \a prec value
- \sa setDecimals()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtRectFPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
- connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)),
- this, SLOT(slotDoubleChanged(QtProperty *, double)));
- connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtRectFPropertyManager::~QtRectFPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the manager that creates the nested \e x, \e y, \e width
- and \e height subproperties.
- In order to provide editing widgets for the mentioned
- subproperties in a property browser widget, this manager must be
- associated with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtDoublePropertyManager *QtRectFPropertyManager::subDoublePropertyManager() const
- {
- return d_ptr->m_doublePropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an invalid rectangle.
- \sa setValue(), constraint()
- */
- QRectF QtRectFPropertyManager::value(const QtProperty *property) const
- {
- return getValue<QRectF>(d_ptr->m_values, property);
- }
- /*!
- Returns the given \a property's precision, in decimals.
- \sa setDecimals()
- */
- int QtRectFPropertyManager::decimals(const QtProperty *property) const
- {
- return getData<int>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::decimals, property, 0);
- }
- /*!
- Returns the given \a property's constraining rectangle. If returned value is null QRectF it means there is no constraint applied.
- \sa value(), setConstraint()
- */
- QRectF QtRectFPropertyManager::constraint(const QtProperty *property) const
- {
- return getData<QRectF>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::constraint, property, QRect());
- }
- /*!
- \reimp
- */
- QString QtRectFPropertyManager::valueText(const QtProperty *property) const
- {
- const QtRectFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QRectF v = it.value().val;
- const int dec = it.value().decimals;
- return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x(), 'f', dec))
- .arg(QString::number(v.y(), 'f', dec))
- .arg(QString::number(v.width(), 'f', dec))
- .arg(QString::number(v.height(), 'f', dec)));
- }
- /*!
- \fn void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- If the specified \a value is not inside the given \a property's
- constraining rectangle, the value is adjusted accordingly to fit
- within the constraint.
- \sa value(), setConstraint(), valueChanged()
- */
- void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &val)
- {
- const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtRectFPropertyManagerPrivate::Data data = it.value();
- QRectF newRect = val.normalized();
- if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
- const QRectF r1 = data.constraint;
- const QRectF r2 = newRect;
- newRect.setLeft(qMax(r1.left(), r2.left()));
- newRect.setRight(qMin(r1.right(), r2.right()));
- newRect.setTop(qMax(r1.top(), r2.top()));
- newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
- if (newRect.width() < 0 || newRect.height() < 0)
- return;
- }
- if (data.val == newRect)
- return;
- data.val = newRect;
- it.value() = data;
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
- d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the given \a property's constraining rectangle to \a
- constraint.
- When setting the constraint, the current value is adjusted if
- necessary (ensuring that the current rectangle value is inside the
- constraint). In order to reset the constraint pass a null QRectF value.
- \sa setValue(), constraint(), constraintChanged()
- */
- void QtRectFPropertyManager::setConstraint(QtProperty *property, const QRectF &constraint)
- {
- const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtRectFPropertyManagerPrivate::Data data = it.value();
- QRectF newConstraint = constraint.normalized();
- if (data.constraint == newConstraint)
- return;
- const QRectF oldVal = data.val;
- data.constraint = newConstraint;
- if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
- QRectF r1 = data.constraint;
- QRectF r2 = data.val;
- if (r2.width() > r1.width())
- r2.setWidth(r1.width());
- if (r2.height() > r1.height())
- r2.setHeight(r1.height());
- if (r2.left() < r1.left())
- r2.moveLeft(r1.left());
- else if (r2.right() > r1.right())
- r2.moveRight(r1.right());
- if (r2.top() < r1.top())
- r2.moveTop(r1.top());
- else if (r2.bottom() > r1.bottom())
- r2.moveBottom(r1.bottom());
- data.val = r2;
- }
- it.value() = data;
- emit constraintChanged(property, data.constraint);
- d_ptr->setConstraint(property, data.constraint, data.val);
- if (data.val == oldVal)
- return;
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- \fn void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
- Sets the precision of the given \a property to \a prec.
- The valid decimal range is 0-13. The default is 2.
- \sa decimals()
- */
- void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
- {
- const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtRectFPropertyManagerPrivate::Data data = it.value();
- if (prec > 13)
- prec = 13;
- else if (prec < 0)
- prec = 0;
- if (data.decimals == prec)
- return;
- data.decimals = prec;
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
- d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
- it.value() = data;
- emit decimalsChanged(property, data.decimals);
- }
- /*!
- \reimp
- */
- void QtRectFPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtRectFPropertyManagerPrivate::Data();
- QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
- xProp->setPropertyName(tr("X"));
- d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(xProp, 0);
- d_ptr->m_propertyToX[property] = xProp;
- d_ptr->m_xToProperty[xProp] = property;
- property->addSubProperty(xProp);
- QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
- yProp->setPropertyName(tr("Y"));
- d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(yProp, 0);
- d_ptr->m_propertyToY[property] = yProp;
- d_ptr->m_yToProperty[yProp] = property;
- property->addSubProperty(yProp);
- QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
- wProp->setPropertyName(tr("Width"));
- d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(wProp, 0);
- d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
- d_ptr->m_propertyToW[property] = wProp;
- d_ptr->m_wToProperty[wProp] = property;
- property->addSubProperty(wProp);
- QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
- hProp->setPropertyName(tr("Height"));
- d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
- d_ptr->m_doublePropertyManager->setValue(hProp, 0);
- d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
- d_ptr->m_propertyToH[property] = hProp;
- d_ptr->m_hToProperty[hProp] = property;
- property->addSubProperty(hProp);
- }
- /*!
- \reimp
- */
- void QtRectFPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *xProp = d_ptr->m_propertyToX[property];
- if (xProp) {
- d_ptr->m_xToProperty.remove(xProp);
- delete xProp;
- }
- d_ptr->m_propertyToX.remove(property);
- QtProperty *yProp = d_ptr->m_propertyToY[property];
- if (yProp) {
- d_ptr->m_yToProperty.remove(yProp);
- delete yProp;
- }
- d_ptr->m_propertyToY.remove(property);
- QtProperty *wProp = d_ptr->m_propertyToW[property];
- if (wProp) {
- d_ptr->m_wToProperty.remove(wProp);
- delete wProp;
- }
- d_ptr->m_propertyToW.remove(property);
- QtProperty *hProp = d_ptr->m_propertyToH[property];
- if (hProp) {
- d_ptr->m_hToProperty.remove(hProp);
- delete hProp;
- }
- d_ptr->m_propertyToH.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtEnumPropertyManager
- class QtEnumPropertyManagerPrivate
- {
- QtEnumPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtEnumPropertyManager)
- public:
- struct Data
- {
- Data() : val(-1) {}
- int val;
- QStringList enumNames;
- QMap<int, QIcon> enumIcons;
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*!
- \class QtEnumPropertyManager
- \brief The QtEnumPropertyManager provides and manages enum properties.
- Each enum property has an associated list of enum names which can
- be retrieved using the enumNames() function, and set using the
- corresponding setEnumNames() function. An enum property's value is
- represented by an index in this list, and can be retrieved and set
- using the value() and setValue() slots respectively.
- Each enum value can also have an associated icon. The mapping from
- values to icons can be set using the setEnumIcons() function and
- queried with the enumIcons() function.
- In addition, QtEnumPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes. The enumNamesChanged() or enumIconsChanged() signal is emitted
- whenever the list of enum names or icons is altered.
- \sa QtAbstractPropertyManager, QtEnumEditorFactory
- */
- /*!
- \fn void QtEnumPropertyManager::valueChanged(QtProperty *property, int value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtEnumPropertyManager::enumNamesChanged(QtProperty *property, const QStringList &names)
- This signal is emitted whenever a property created by this manager
- changes its enum names, passing a pointer to the \a property and
- the new \a names as parameters.
- \sa setEnumNames()
- */
- /*!
- \fn void QtEnumPropertyManager::enumIconsChanged(QtProperty *property, const QMap<int, QIcon> &icons)
- This signal is emitted whenever a property created by this manager
- changes its enum icons, passing a pointer to the \a property and
- the new mapping of values to \a icons as parameters.
- \sa setEnumIcons()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtEnumPropertyManager::QtEnumPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtEnumPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtEnumPropertyManager::~QtEnumPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property's value which is an index in the
- list returned by enumNames()
- If the given property is not managed by this manager, this
- function returns -1.
- \sa enumNames(), setValue()
- */
- int QtEnumPropertyManager::value(const QtProperty *property) const
- {
- return getValue<int>(d_ptr->m_values, property, -1);
- }
- /*!
- Returns the given \a property's list of enum names.
- \sa value(), setEnumNames()
- */
- QStringList QtEnumPropertyManager::enumNames(const QtProperty *property) const
- {
- return getData<QStringList>(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumNames, property, QStringList());
- }
- /*!
- Returns the given \a property's map of enum values to their icons.
- \sa value(), setEnumIcons()
- */
- QMap<int, QIcon> QtEnumPropertyManager::enumIcons(const QtProperty *property) const
- {
- return getData<QMap<int, QIcon> >(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumIcons, property, QMap<int, QIcon>());
- }
- /*!
- \reimp
- */
- QString QtEnumPropertyManager::valueText(const QtProperty *property) const
- {
- const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QtEnumPropertyManagerPrivate::Data &data = it.value();
- const int v = data.val;
- if (v >= 0 && v < data.enumNames.count())
- return data.enumNames.at(v);
- return QString();
- }
- /*!
- \reimp
- */
- QIcon QtEnumPropertyManager::valueIcon(const QtProperty *property) const
- {
- const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QIcon();
- const QtEnumPropertyManagerPrivate::Data &data = it.value();
- const int v = data.val;
- return data.enumIcons.value(v);
- }
- /*!
- \fn void QtEnumPropertyManager::setValue(QtProperty *property, int value)
- Sets the value of the given \a property to \a value.
- The specified \a value must be less than the size of the given \a
- property's enumNames() list, and larger than (or equal to) 0.
- \sa value(), valueChanged()
- */
- void QtEnumPropertyManager::setValue(QtProperty *property, int val)
- {
- const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtEnumPropertyManagerPrivate::Data data = it.value();
- if (val >= data.enumNames.count())
- return;
- if (val < 0 && data.enumNames.count() > 0)
- return;
- if (val < 0)
- val = -1;
- if (data.val == val)
- return;
- data.val = val;
- it.value() = data;
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the given \a property's list of enum names to \a
- enumNames. The \a property's current value is reset to 0
- indicating the first item of the list.
- If the specified \a enumNames list is empty, the \a property's
- current value is set to -1.
- \sa enumNames(), enumNamesChanged()
- */
- void QtEnumPropertyManager::setEnumNames(QtProperty *property, const QStringList &enumNames)
- {
- const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtEnumPropertyManagerPrivate::Data data = it.value();
- if (data.enumNames == enumNames)
- return;
- data.enumNames = enumNames;
- data.val = -1;
- if (enumNames.count() > 0)
- data.val = 0;
- it.value() = data;
- emit enumNamesChanged(property, data.enumNames);
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the given \a property's map of enum values to their icons to \a
- enumIcons.
- Each enum value can have associated icon. This association is represented with passed \a enumIcons map.
- \sa enumNames(), enumNamesChanged()
- */
- void QtEnumPropertyManager::setEnumIcons(QtProperty *property, const QMap<int, QIcon> &enumIcons)
- {
- const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- it.value().enumIcons = enumIcons;
- emit enumIconsChanged(property, it.value().enumIcons);
- emit propertyChanged(property);
- }
- /*!
- \reimp
- */
- void QtEnumPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtEnumPropertyManagerPrivate::Data();
- }
- /*!
- \reimp
- */
- void QtEnumPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- // QtFlagPropertyManager
- class QtFlagPropertyManagerPrivate
- {
- QtFlagPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtFlagPropertyManager)
- public:
- void slotBoolChanged(QtProperty *property, bool value);
- void slotPropertyDestroyed(QtProperty *property);
- struct Data
- {
- Data() : val(-1) {}
- int val;
- QStringList flagNames;
- };
- typedef QMap<const QtProperty *, Data> PropertyValueMap;
- PropertyValueMap m_values;
- QtBoolPropertyManager *m_boolPropertyManager;
- QMap<const QtProperty *, QList<QtProperty *> > m_propertyToFlags;
- QMap<const QtProperty *, QtProperty *> m_flagToProperty;
- };
- void QtFlagPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
- {
- QtProperty *prop = m_flagToProperty.value(property, 0);
- if (prop == 0)
- return;
- QListIterator<QtProperty *> itProp(m_propertyToFlags[prop]);
- int level = 0;
- while (itProp.hasNext()) {
- QtProperty *p = itProp.next();
- if (p == property) {
- int v = m_values[prop].val;
- if (value) {
- v |= (1 << level);
- } else {
- v &= ~(1 << level);
- }
- q_ptr->setValue(prop, v);
- return;
- }
- level++;
- }
- }
- void QtFlagPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- QtProperty *flagProperty = m_flagToProperty.value(property, 0);
- if (flagProperty == 0)
- return;
- m_propertyToFlags[flagProperty].replace(m_propertyToFlags[flagProperty].indexOf(property), 0);
- m_flagToProperty.remove(property);
- }
- /*!
- \class QtFlagPropertyManager
- \brief The QtFlagPropertyManager provides and manages flag properties.
- Each flag property has an associated list of flag names which can
- be retrieved using the flagNames() function, and set using the
- corresponding setFlagNames() function.
- The flag manager provides properties with nested boolean
- subproperties representing each flag, i.e. a flag property's value
- is the binary combination of the subproperties' values. A
- property's value can be retrieved and set using the value() and
- setValue() slots respectively. The combination of flags is represented
- by single int value - that's why it's possible to store up to
- 32 independent flags in one flag property.
- The subproperties are created by a QtBoolPropertyManager object. This
- manager can be retrieved using the subBoolPropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- In addition, QtFlagPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes, and the flagNamesChanged() signal which is emitted
- whenever the list of flag names is altered.
- \sa QtAbstractPropertyManager, QtBoolPropertyManager
- */
- /*!
- \fn void QtFlagPropertyManager::valueChanged(QtProperty *property, int value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- \fn void QtFlagPropertyManager::flagNamesChanged(QtProperty *property, const QStringList &names)
- This signal is emitted whenever a property created by this manager
- changes its flag names, passing a pointer to the \a property and the
- new \a names as parameters.
- \sa setFlagNames()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtFlagPropertyManager::QtFlagPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtFlagPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
- connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty *, bool)),
- this, SLOT(slotBoolChanged(QtProperty *, bool)));
- connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtFlagPropertyManager::~QtFlagPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the manager that produces the nested boolean subproperties
- representing each flag.
- In order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtBoolPropertyManager *QtFlagPropertyManager::subBoolPropertyManager() const
- {
- return d_ptr->m_boolPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns 0.
- \sa flagNames(), setValue()
- */
- int QtFlagPropertyManager::value(const QtProperty *property) const
- {
- return getValue<int>(d_ptr->m_values, property, 0);
- }
- /*!
- Returns the given \a property's list of flag names.
- \sa value(), setFlagNames()
- */
- QStringList QtFlagPropertyManager::flagNames(const QtProperty *property) const
- {
- return getData<QStringList>(d_ptr->m_values, &QtFlagPropertyManagerPrivate::Data::flagNames, property, QStringList());
- }
- /*!
- \reimp
- */
- QString QtFlagPropertyManager::valueText(const QtProperty *property) const
- {
- const QtFlagPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QtFlagPropertyManagerPrivate::Data &data = it.value();
- QString str;
- int level = 0;
- const QChar bar = QLatin1Char('|');
- const QStringList::const_iterator fncend = data.flagNames.constEnd();
- for (QStringList::const_iterator it = data.flagNames.constBegin(); it != fncend; ++it) {
- if (data.val & (1 << level)) {
- if (!str.isEmpty())
- str += bar;
- str += *it;
- }
- level++;
- }
- return str;
- }
- /*!
- \fn void QtFlagPropertyManager::setValue(QtProperty *property, int value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- The specified \a value must be less than the binary combination of
- the property's flagNames() list size (i.e. less than 2\sup n,
- where \c n is the size of the list) and larger than (or equal to)
- 0.
- \sa value(), valueChanged()
- */
- void QtFlagPropertyManager::setValue(QtProperty *property, int val)
- {
- const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtFlagPropertyManagerPrivate::Data data = it.value();
- if (data.val == val)
- return;
- if (val > (1 << data.flagNames.count()) - 1)
- return;
- if (val < 0)
- return;
- data.val = val;
- it.value() = data;
- QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
- int level = 0;
- while (itProp.hasNext()) {
- QtProperty *prop = itProp.next();
- if (prop)
- d_ptr->m_boolPropertyManager->setValue(prop, val & (1 << level));
- level++;
- }
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- Sets the given \a property's list of flag names to \a flagNames. The
- property's current value is reset to 0 indicating the first item
- of the list.
- \sa flagNames(), flagNamesChanged()
- */
- void QtFlagPropertyManager::setFlagNames(QtProperty *property, const QStringList &flagNames)
- {
- const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- QtFlagPropertyManagerPrivate::Data data = it.value();
- if (data.flagNames == flagNames)
- return;
- data.flagNames = flagNames;
- data.val = 0;
- it.value() = data;
- QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
- while (itProp.hasNext()) {
- QtProperty *prop = itProp.next();
- if (prop) {
- delete prop;
- d_ptr->m_flagToProperty.remove(prop);
- }
- }
- d_ptr->m_propertyToFlags[property].clear();
- QStringListIterator itFlag(flagNames);
- while (itFlag.hasNext()) {
- const QString flagName = itFlag.next();
- QtProperty *prop = d_ptr->m_boolPropertyManager->addProperty();
- prop->setPropertyName(flagName);
- property->addSubProperty(prop);
- d_ptr->m_propertyToFlags[property].append(prop);
- d_ptr->m_flagToProperty[prop] = property;
- }
- emit flagNamesChanged(property, data.flagNames);
- emit propertyChanged(property);
- emit valueChanged(property, data.val);
- }
- /*!
- \reimp
- */
- void QtFlagPropertyManager::initializeProperty(QtProperty *property)
- {
- d_ptr->m_values[property] = QtFlagPropertyManagerPrivate::Data();
- d_ptr->m_propertyToFlags[property] = QList<QtProperty *>();
- }
- /*!
- \reimp
- */
- void QtFlagPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
- while (itProp.hasNext()) {
- QtProperty *prop = itProp.next();
- if (prop) {
- delete prop;
- d_ptr->m_flagToProperty.remove(prop);
- }
- }
- d_ptr->m_propertyToFlags.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtSizePolicyPropertyManager
- class QtSizePolicyPropertyManagerPrivate
- {
- QtSizePolicyPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtSizePolicyPropertyManager)
- public:
- QtSizePolicyPropertyManagerPrivate();
- void slotIntChanged(QtProperty *property, int value);
- void slotEnumChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- typedef QMap<const QtProperty *, QSizePolicy> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QtEnumPropertyManager *m_enumPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToHPolicy;
- QMap<const QtProperty *, QtProperty *> m_propertyToVPolicy;
- QMap<const QtProperty *, QtProperty *> m_propertyToHStretch;
- QMap<const QtProperty *, QtProperty *> m_propertyToVStretch;
- QMap<const QtProperty *, QtProperty *> m_hPolicyToProperty;
- QMap<const QtProperty *, QtProperty *> m_vPolicyToProperty;
- QMap<const QtProperty *, QtProperty *> m_hStretchToProperty;
- QMap<const QtProperty *, QtProperty *> m_vStretchToProperty;
- };
- QtSizePolicyPropertyManagerPrivate::QtSizePolicyPropertyManagerPrivate()
- {
- }
- void QtSizePolicyPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_hStretchToProperty.value(property, 0)) {
- QSizePolicy sp = m_values[prop];
- sp.setHorizontalStretch(value);
- q_ptr->setValue(prop, sp);
- } else if (QtProperty *prop = m_vStretchToProperty.value(property, 0)) {
- QSizePolicy sp = m_values[prop];
- sp.setVerticalStretch(value);
- q_ptr->setValue(prop, sp);
- }
- }
- void QtSizePolicyPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_hPolicyToProperty.value(property, 0)) {
- QSizePolicy sp = m_values[prop];
- sp.setHorizontalPolicy(metaEnumProvider()->indexToSizePolicy(value));
- q_ptr->setValue(prop, sp);
- } else if (QtProperty *prop = m_vPolicyToProperty.value(property, 0)) {
- QSizePolicy sp = m_values[prop];
- sp.setVerticalPolicy(metaEnumProvider()->indexToSizePolicy(value));
- q_ptr->setValue(prop, sp);
- }
- }
- void QtSizePolicyPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_hStretchToProperty.value(property, 0)) {
- m_propertyToHStretch[pointProp] = 0;
- m_hStretchToProperty.remove(property);
- } else if (QtProperty *pointProp = m_vStretchToProperty.value(property, 0)) {
- m_propertyToVStretch[pointProp] = 0;
- m_vStretchToProperty.remove(property);
- } else if (QtProperty *pointProp = m_hPolicyToProperty.value(property, 0)) {
- m_propertyToHPolicy[pointProp] = 0;
- m_hPolicyToProperty.remove(property);
- } else if (QtProperty *pointProp = m_vPolicyToProperty.value(property, 0)) {
- m_propertyToVPolicy[pointProp] = 0;
- m_vPolicyToProperty.remove(property);
- }
- }
- /*!
- \class QtSizePolicyPropertyManager
- \brief The QtSizePolicyPropertyManager provides and manages QSizePolicy properties.
- A size policy property has nested \e horizontalPolicy, \e
- verticalPolicy, \e horizontalStretch and \e verticalStretch
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by QtIntPropertyManager and QtEnumPropertyManager
- objects. These managers can be retrieved using the subIntPropertyManager()
- and subEnumPropertyManager() functions respectively. In order to provide
- editing widgets for the subproperties in a property browser widget,
- these managers must be associated with editor factories.
- In addition, QtSizePolicyPropertyManager provides the valueChanged()
- signal which is emitted whenever a property created by this
- manager changes.
- \sa QtAbstractPropertyManager, QtIntPropertyManager, QtEnumPropertyManager
- */
- /*!
- \fn void QtSizePolicyPropertyManager::valueChanged(QtProperty *property, const QSizePolicy &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtSizePolicyPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotIntChanged(QtProperty *, int)));
- d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
- connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotEnumChanged(QtProperty *, int)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtSizePolicyPropertyManager::~QtSizePolicyPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the manager that creates the nested \e horizontalStretch
- and \e verticalStretch subproperties.
- In order to provide editing widgets for the mentioned subproperties
- in a property browser widget, this manager must be associated with
- an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtSizePolicyPropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the manager that creates the nested \e horizontalPolicy
- and \e verticalPolicy subproperties.
- In order to provide editing widgets for the mentioned subproperties
- in a property browser widget, this manager must be associated with
- an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtEnumPropertyManager *QtSizePolicyPropertyManager::subEnumPropertyManager() const
- {
- return d_ptr->m_enumPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns the default size policy.
- \sa setValue()
- */
- QSizePolicy QtSizePolicyPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QSizePolicy());
- }
- /*!
- \reimp
- */
- QString QtSizePolicyPropertyManager::valueText(const QtProperty *property) const
- {
- const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- const QSizePolicy sp = it.value();
- const QtMetaEnumProvider *mep = metaEnumProvider();
- const int hIndex = mep->sizePolicyToIndex(sp.horizontalPolicy());
- const int vIndex = mep->sizePolicyToIndex(sp.verticalPolicy());
- //! Unknown size policy on reading invalid uic3 files
- const QString hPolicy = hIndex != -1 ? mep->policyEnumNames().at(hIndex) : tr("<Invalid>");
- const QString vPolicy = vIndex != -1 ? mep->policyEnumNames().at(vIndex) : tr("<Invalid>");
- const QString str = tr("[%1, %2, %3, %4]").arg(hPolicy, vPolicy).arg(sp.horizontalStretch()).arg(sp.verticalStretch());
- return str;
- }
- /*!
- \fn void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &val)
- {
- const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- if (it.value() == val)
- return;
- it.value() = val;
- d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToHPolicy[property],
- metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
- d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToVPolicy[property],
- metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToHStretch[property],
- val.horizontalStretch());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToVStretch[property],
- val.verticalStretch());
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \reimp
- */
- void QtSizePolicyPropertyManager::initializeProperty(QtProperty *property)
- {
- QSizePolicy val;
- d_ptr->m_values[property] = val;
- QtProperty *hPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
- hPolicyProp->setPropertyName(tr("Horizontal Policy"));
- d_ptr->m_enumPropertyManager->setEnumNames(hPolicyProp, metaEnumProvider()->policyEnumNames());
- d_ptr->m_enumPropertyManager->setValue(hPolicyProp,
- metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
- d_ptr->m_propertyToHPolicy[property] = hPolicyProp;
- d_ptr->m_hPolicyToProperty[hPolicyProp] = property;
- property->addSubProperty(hPolicyProp);
- QtProperty *vPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
- vPolicyProp->setPropertyName(tr("Vertical Policy"));
- d_ptr->m_enumPropertyManager->setEnumNames(vPolicyProp, metaEnumProvider()->policyEnumNames());
- d_ptr->m_enumPropertyManager->setValue(vPolicyProp,
- metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
- d_ptr->m_propertyToVPolicy[property] = vPolicyProp;
- d_ptr->m_vPolicyToProperty[vPolicyProp] = property;
- property->addSubProperty(vPolicyProp);
- QtProperty *hStretchProp = d_ptr->m_intPropertyManager->addProperty();
- hStretchProp->setPropertyName(tr("Horizontal Stretch"));
- d_ptr->m_intPropertyManager->setValue(hStretchProp, val.horizontalStretch());
- d_ptr->m_intPropertyManager->setRange(hStretchProp, 0, 0xff);
- d_ptr->m_propertyToHStretch[property] = hStretchProp;
- d_ptr->m_hStretchToProperty[hStretchProp] = property;
- property->addSubProperty(hStretchProp);
- QtProperty *vStretchProp = d_ptr->m_intPropertyManager->addProperty();
- vStretchProp->setPropertyName(tr("Vertical Stretch"));
- d_ptr->m_intPropertyManager->setValue(vStretchProp, val.verticalStretch());
- d_ptr->m_intPropertyManager->setRange(vStretchProp, 0, 0xff);
- d_ptr->m_propertyToVStretch[property] = vStretchProp;
- d_ptr->m_vStretchToProperty[vStretchProp] = property;
- property->addSubProperty(vStretchProp);
- }
- /*!
- \reimp
- */
- void QtSizePolicyPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *hPolicyProp = d_ptr->m_propertyToHPolicy[property];
- if (hPolicyProp) {
- d_ptr->m_hPolicyToProperty.remove(hPolicyProp);
- delete hPolicyProp;
- }
- d_ptr->m_propertyToHPolicy.remove(property);
- QtProperty *vPolicyProp = d_ptr->m_propertyToVPolicy[property];
- if (vPolicyProp) {
- d_ptr->m_vPolicyToProperty.remove(vPolicyProp);
- delete vPolicyProp;
- }
- d_ptr->m_propertyToVPolicy.remove(property);
- QtProperty *hStretchProp = d_ptr->m_propertyToHStretch[property];
- if (hStretchProp) {
- d_ptr->m_hStretchToProperty.remove(hStretchProp);
- delete hStretchProp;
- }
- d_ptr->m_propertyToHStretch.remove(property);
- QtProperty *vStretchProp = d_ptr->m_propertyToVStretch[property];
- if (vStretchProp) {
- d_ptr->m_vStretchToProperty.remove(vStretchProp);
- delete vStretchProp;
- }
- d_ptr->m_propertyToVStretch.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtFontPropertyManager:
- // QtFontPropertyManagerPrivate has a mechanism for reacting
- // to QApplication::fontDatabaseChanged() [4.5], which is emitted
- // when someone loads an application font. The signals are compressed
- // using a timer with interval 0, which then causes the family
- // enumeration manager to re-set its strings and index values
- // for each property.
- Q_GLOBAL_STATIC(QFontDatabase, fontDatabase)
- class QtFontPropertyManagerPrivate
- {
- QtFontPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtFontPropertyManager)
- public:
- QtFontPropertyManagerPrivate();
- void slotIntChanged(QtProperty *property, int value);
- void slotEnumChanged(QtProperty *property, int value);
- void slotBoolChanged(QtProperty *property, bool value);
- void slotPropertyDestroyed(QtProperty *property);
- void slotFontDatabaseChanged();
- void slotFontDatabaseDelayedChange();
- QStringList m_familyNames;
- typedef QMap<const QtProperty *, QFont> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QtEnumPropertyManager *m_enumPropertyManager;
- QtBoolPropertyManager *m_boolPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToFamily;
- QMap<const QtProperty *, QtProperty *> m_propertyToPointSize;
- QMap<const QtProperty *, QtProperty *> m_propertyToBold;
- QMap<const QtProperty *, QtProperty *> m_propertyToItalic;
- QMap<const QtProperty *, QtProperty *> m_propertyToUnderline;
- QMap<const QtProperty *, QtProperty *> m_propertyToStrikeOut;
- QMap<const QtProperty *, QtProperty *> m_propertyToKerning;
- QMap<const QtProperty *, QtProperty *> m_familyToProperty;
- QMap<const QtProperty *, QtProperty *> m_pointSizeToProperty;
- QMap<const QtProperty *, QtProperty *> m_boldToProperty;
- QMap<const QtProperty *, QtProperty *> m_italicToProperty;
- QMap<const QtProperty *, QtProperty *> m_underlineToProperty;
- QMap<const QtProperty *, QtProperty *> m_strikeOutToProperty;
- QMap<const QtProperty *, QtProperty *> m_kerningToProperty;
- bool m_settingValue;
- QTimer *m_fontDatabaseChangeTimer;
- };
- QtFontPropertyManagerPrivate::QtFontPropertyManagerPrivate() :
- m_settingValue(false),
- m_fontDatabaseChangeTimer(0)
- {
- }
- void QtFontPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (m_settingValue)
- return;
- if (QtProperty *prop = m_pointSizeToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setPointSize(value);
- q_ptr->setValue(prop, f);
- }
- }
- void QtFontPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
- {
- if (m_settingValue)
- return;
- if (QtProperty *prop = m_familyToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setFamily(m_familyNames.at(value));
- q_ptr->setValue(prop, f);
- }
- }
- void QtFontPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
- {
- if (m_settingValue)
- return;
- if (QtProperty *prop = m_boldToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setBold(value);
- q_ptr->setValue(prop, f);
- } else if (QtProperty *prop = m_italicToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setItalic(value);
- q_ptr->setValue(prop, f);
- } else if (QtProperty *prop = m_underlineToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setUnderline(value);
- q_ptr->setValue(prop, f);
- } else if (QtProperty *prop = m_strikeOutToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setStrikeOut(value);
- q_ptr->setValue(prop, f);
- } else if (QtProperty *prop = m_kerningToProperty.value(property, 0)) {
- QFont f = m_values[prop];
- f.setKerning(value);
- q_ptr->setValue(prop, f);
- }
- }
- void QtFontPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_pointSizeToProperty.value(property, 0)) {
- m_propertyToPointSize[pointProp] = 0;
- m_pointSizeToProperty.remove(property);
- } else if (QtProperty *pointProp = m_familyToProperty.value(property, 0)) {
- m_propertyToFamily[pointProp] = 0;
- m_familyToProperty.remove(property);
- } else if (QtProperty *pointProp = m_boldToProperty.value(property, 0)) {
- m_propertyToBold[pointProp] = 0;
- m_boldToProperty.remove(property);
- } else if (QtProperty *pointProp = m_italicToProperty.value(property, 0)) {
- m_propertyToItalic[pointProp] = 0;
- m_italicToProperty.remove(property);
- } else if (QtProperty *pointProp = m_underlineToProperty.value(property, 0)) {
- m_propertyToUnderline[pointProp] = 0;
- m_underlineToProperty.remove(property);
- } else if (QtProperty *pointProp = m_strikeOutToProperty.value(property, 0)) {
- m_propertyToStrikeOut[pointProp] = 0;
- m_strikeOutToProperty.remove(property);
- } else if (QtProperty *pointProp = m_kerningToProperty.value(property, 0)) {
- m_propertyToKerning[pointProp] = 0;
- m_kerningToProperty.remove(property);
- }
- }
- void QtFontPropertyManagerPrivate::slotFontDatabaseChanged()
- {
- if (!m_fontDatabaseChangeTimer) {
- m_fontDatabaseChangeTimer = new QTimer(q_ptr);
- m_fontDatabaseChangeTimer->setInterval(0);
- m_fontDatabaseChangeTimer->setSingleShot(true);
- QObject::connect(m_fontDatabaseChangeTimer, SIGNAL(timeout()), q_ptr, SLOT(slotFontDatabaseDelayedChange()));
- }
- if (!m_fontDatabaseChangeTimer->isActive())
- m_fontDatabaseChangeTimer->start();
- }
- void QtFontPropertyManagerPrivate::slotFontDatabaseDelayedChange()
- {
- typedef QMap<const QtProperty *, QtProperty *> PropertyPropertyMap;
- // rescan available font names
- const QStringList oldFamilies = m_familyNames;
- m_familyNames = fontDatabase()->families();
- // Adapt all existing properties
- if (!m_propertyToFamily.empty()) {
- PropertyPropertyMap::const_iterator cend = m_propertyToFamily.constEnd();
- for (PropertyPropertyMap::const_iterator it = m_propertyToFamily.constBegin(); it != cend; ++it) {
- QtProperty *familyProp = it.value();
- const int oldIdx = m_enumPropertyManager->value(familyProp);
- int newIdx = m_familyNames.indexOf(oldFamilies.at(oldIdx));
- if (newIdx < 0)
- newIdx = 0;
- m_enumPropertyManager->setEnumNames(familyProp, m_familyNames);
- m_enumPropertyManager->setValue(familyProp, newIdx);
- }
- }
- }
- /*!
- \class QtFontPropertyManager
- \brief The QtFontPropertyManager provides and manages QFont properties.
- A font property has nested \e family, \e pointSize, \e bold, \e
- italic, \e underline, \e strikeOut and \e kerning subproperties. The top-level
- property's value can be retrieved using the value() function, and
- set using the setValue() slot.
- The subproperties are created by QtIntPropertyManager, QtEnumPropertyManager and
- QtBoolPropertyManager objects. These managers can be retrieved using the
- corresponding subIntPropertyManager(), subEnumPropertyManager() and
- subBoolPropertyManager() functions. In order to provide editing widgets
- for the subproperties in a property browser widget, these managers
- must be associated with editor factories.
- In addition, QtFontPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager, QtEnumPropertyManager, QtIntPropertyManager, QtBoolPropertyManager
- */
- /*!
- \fn void QtFontPropertyManager::valueChanged(QtProperty *property, const QFont &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the
- new \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtFontPropertyManager::QtFontPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtFontPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- #if QT_VERSION >= 0x040500
- QObject::connect(qApp, SIGNAL(fontDatabaseChanged()), this, SLOT(slotFontDatabaseChanged()));
- #endif
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotIntChanged(QtProperty *, int)));
- d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
- connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotEnumChanged(QtProperty *, int)));
- d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
- connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty *, bool)),
- this, SLOT(slotBoolChanged(QtProperty *, bool)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtFontPropertyManager::~QtFontPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the manager that creates the \e pointSize subproperty.
- In order to provide editing widgets for the \e pointSize property
- in a property browser widget, this manager must be associated
- with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtFontPropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the manager that create the \e family subproperty.
- In order to provide editing widgets for the \e family property
- in a property browser widget, this manager must be associated
- with an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtEnumPropertyManager *QtFontPropertyManager::subEnumPropertyManager() const
- {
- return d_ptr->m_enumPropertyManager;
- }
- /*!
- Returns the manager that creates the \e bold, \e italic, \e underline,
- \e strikeOut and \e kerning subproperties.
- In order to provide editing widgets for the mentioned properties
- in a property browser widget, this manager must be associated with
- an editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtBoolPropertyManager *QtFontPropertyManager::subBoolPropertyManager() const
- {
- return d_ptr->m_boolPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given property is not managed by this manager, this
- function returns a font object that uses the application's default
- font.
- \sa setValue()
- */
- QFont QtFontPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QFont());
- }
- /*!
- \reimp
- */
- QString QtFontPropertyManager::valueText(const QtProperty *property) const
- {
- const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return QtPropertyBrowserUtils::fontValueText(it.value());
- }
- /*!
- \reimp
- */
- QIcon QtFontPropertyManager::valueIcon(const QtProperty *property) const
- {
- const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QIcon();
- return QtPropertyBrowserUtils::fontValueIcon(it.value());
- }
- /*!
- \fn void QtFontPropertyManager::setValue(QtProperty *property, const QFont &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtFontPropertyManager::setValue(QtProperty *property, const QFont &val)
- {
- const QtFontPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- const QFont oldVal = it.value();
- if (oldVal == val && oldVal.resolve() == val.resolve())
- return;
- it.value() = val;
- int idx = d_ptr->m_familyNames.indexOf(val.family());
- if (idx == -1)
- idx = 0;
- bool settingValue = d_ptr->m_settingValue;
- d_ptr->m_settingValue = true;
- d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToFamily[property], idx);
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToPointSize[property], val.pointSize());
- d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToBold[property], val.bold());
- d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToItalic[property], val.italic());
- d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToUnderline[property], val.underline());
- d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToStrikeOut[property], val.strikeOut());
- d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToKerning[property], val.kerning());
- d_ptr->m_settingValue = settingValue;
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \reimp
- */
- void QtFontPropertyManager::initializeProperty(QtProperty *property)
- {
- QFont val;
- d_ptr->m_values[property] = val;
- QtProperty *familyProp = d_ptr->m_enumPropertyManager->addProperty();
- familyProp->setPropertyName(tr("Family"));
- if (d_ptr->m_familyNames.empty())
- d_ptr->m_familyNames = fontDatabase()->families();
- d_ptr->m_enumPropertyManager->setEnumNames(familyProp, d_ptr->m_familyNames);
- int idx = d_ptr->m_familyNames.indexOf(val.family());
- if (idx == -1)
- idx = 0;
- d_ptr->m_enumPropertyManager->setValue(familyProp, idx);
- d_ptr->m_propertyToFamily[property] = familyProp;
- d_ptr->m_familyToProperty[familyProp] = property;
- property->addSubProperty(familyProp);
- QtProperty *pointSizeProp = d_ptr->m_intPropertyManager->addProperty();
- pointSizeProp->setPropertyName(tr("Point Size"));
- d_ptr->m_intPropertyManager->setValue(pointSizeProp, val.pointSize());
- d_ptr->m_intPropertyManager->setMinimum(pointSizeProp, 1);
- d_ptr->m_propertyToPointSize[property] = pointSizeProp;
- d_ptr->m_pointSizeToProperty[pointSizeProp] = property;
- property->addSubProperty(pointSizeProp);
- QtProperty *boldProp = d_ptr->m_boolPropertyManager->addProperty();
- boldProp->setPropertyName(tr("Bold"));
- d_ptr->m_boolPropertyManager->setValue(boldProp, val.bold());
- d_ptr->m_propertyToBold[property] = boldProp;
- d_ptr->m_boldToProperty[boldProp] = property;
- property->addSubProperty(boldProp);
- QtProperty *italicProp = d_ptr->m_boolPropertyManager->addProperty();
- italicProp->setPropertyName(tr("Italic"));
- d_ptr->m_boolPropertyManager->setValue(italicProp, val.italic());
- d_ptr->m_propertyToItalic[property] = italicProp;
- d_ptr->m_italicToProperty[italicProp] = property;
- property->addSubProperty(italicProp);
- QtProperty *underlineProp = d_ptr->m_boolPropertyManager->addProperty();
- underlineProp->setPropertyName(tr("Underline"));
- d_ptr->m_boolPropertyManager->setValue(underlineProp, val.underline());
- d_ptr->m_propertyToUnderline[property] = underlineProp;
- d_ptr->m_underlineToProperty[underlineProp] = property;
- property->addSubProperty(underlineProp);
- QtProperty *strikeOutProp = d_ptr->m_boolPropertyManager->addProperty();
- strikeOutProp->setPropertyName(tr("Strikeout"));
- d_ptr->m_boolPropertyManager->setValue(strikeOutProp, val.strikeOut());
- d_ptr->m_propertyToStrikeOut[property] = strikeOutProp;
- d_ptr->m_strikeOutToProperty[strikeOutProp] = property;
- property->addSubProperty(strikeOutProp);
- QtProperty *kerningProp = d_ptr->m_boolPropertyManager->addProperty();
- kerningProp->setPropertyName(tr("Kerning"));
- d_ptr->m_boolPropertyManager->setValue(kerningProp, val.kerning());
- d_ptr->m_propertyToKerning[property] = kerningProp;
- d_ptr->m_kerningToProperty[kerningProp] = property;
- property->addSubProperty(kerningProp);
- }
- /*!
- \reimp
- */
- void QtFontPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *familyProp = d_ptr->m_propertyToFamily[property];
- if (familyProp) {
- d_ptr->m_familyToProperty.remove(familyProp);
- delete familyProp;
- }
- d_ptr->m_propertyToFamily.remove(property);
- QtProperty *pointSizeProp = d_ptr->m_propertyToPointSize[property];
- if (pointSizeProp) {
- d_ptr->m_pointSizeToProperty.remove(pointSizeProp);
- delete pointSizeProp;
- }
- d_ptr->m_propertyToPointSize.remove(property);
- QtProperty *boldProp = d_ptr->m_propertyToBold[property];
- if (boldProp) {
- d_ptr->m_boldToProperty.remove(boldProp);
- delete boldProp;
- }
- d_ptr->m_propertyToBold.remove(property);
- QtProperty *italicProp = d_ptr->m_propertyToItalic[property];
- if (italicProp) {
- d_ptr->m_italicToProperty.remove(italicProp);
- delete italicProp;
- }
- d_ptr->m_propertyToItalic.remove(property);
- QtProperty *underlineProp = d_ptr->m_propertyToUnderline[property];
- if (underlineProp) {
- d_ptr->m_underlineToProperty.remove(underlineProp);
- delete underlineProp;
- }
- d_ptr->m_propertyToUnderline.remove(property);
- QtProperty *strikeOutProp = d_ptr->m_propertyToStrikeOut[property];
- if (strikeOutProp) {
- d_ptr->m_strikeOutToProperty.remove(strikeOutProp);
- delete strikeOutProp;
- }
- d_ptr->m_propertyToStrikeOut.remove(property);
- QtProperty *kerningProp = d_ptr->m_propertyToKerning[property];
- if (kerningProp) {
- d_ptr->m_kerningToProperty.remove(kerningProp);
- delete kerningProp;
- }
- d_ptr->m_propertyToKerning.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtColorPropertyManager
- class QtColorPropertyManagerPrivate
- {
- QtColorPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtColorPropertyManager)
- public:
- void slotIntChanged(QtProperty *property, int value);
- void slotPropertyDestroyed(QtProperty *property);
- typedef QMap<const QtProperty *, QColor> PropertyValueMap;
- PropertyValueMap m_values;
- QtIntPropertyManager *m_intPropertyManager;
- QMap<const QtProperty *, QtProperty *> m_propertyToR;
- QMap<const QtProperty *, QtProperty *> m_propertyToG;
- QMap<const QtProperty *, QtProperty *> m_propertyToB;
- QMap<const QtProperty *, QtProperty *> m_propertyToA;
- QMap<const QtProperty *, QtProperty *> m_rToProperty;
- QMap<const QtProperty *, QtProperty *> m_gToProperty;
- QMap<const QtProperty *, QtProperty *> m_bToProperty;
- QMap<const QtProperty *, QtProperty *> m_aToProperty;
- };
- void QtColorPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
- {
- if (QtProperty *prop = m_rToProperty.value(property, 0)) {
- QColor c = m_values[prop];
- c.setRed(value);
- q_ptr->setValue(prop, c);
- } else if (QtProperty *prop = m_gToProperty.value(property, 0)) {
- QColor c = m_values[prop];
- c.setGreen(value);
- q_ptr->setValue(prop, c);
- } else if (QtProperty *prop = m_bToProperty.value(property, 0)) {
- QColor c = m_values[prop];
- c.setBlue(value);
- q_ptr->setValue(prop, c);
- } else if (QtProperty *prop = m_aToProperty.value(property, 0)) {
- QColor c = m_values[prop];
- c.setAlpha(value);
- q_ptr->setValue(prop, c);
- }
- }
- void QtColorPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
- {
- if (QtProperty *pointProp = m_rToProperty.value(property, 0)) {
- m_propertyToR[pointProp] = 0;
- m_rToProperty.remove(property);
- } else if (QtProperty *pointProp = m_gToProperty.value(property, 0)) {
- m_propertyToG[pointProp] = 0;
- m_gToProperty.remove(property);
- } else if (QtProperty *pointProp = m_bToProperty.value(property, 0)) {
- m_propertyToB[pointProp] = 0;
- m_bToProperty.remove(property);
- } else if (QtProperty *pointProp = m_aToProperty.value(property, 0)) {
- m_propertyToA[pointProp] = 0;
- m_aToProperty.remove(property);
- }
- }
- /*!
- \class QtColorPropertyManager
- \brief The QtColorPropertyManager provides and manages QColor properties.
- A color property has nested \e red, \e green and \e blue
- subproperties. The top-level property's value can be retrieved
- using the value() function, and set using the setValue() slot.
- The subproperties are created by a QtIntPropertyManager object. This
- manager can be retrieved using the subIntPropertyManager() function. In
- order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- In addition, QtColorPropertyManager provides the valueChanged() signal
- which is emitted whenever a property created by this manager
- changes.
- \sa QtAbstractPropertyManager, QtAbstractPropertyBrowser, QtIntPropertyManager
- */
- /*!
- \fn void QtColorPropertyManager::valueChanged(QtProperty *property, const QColor &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtColorPropertyManager::QtColorPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtColorPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
- connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotIntChanged(QtProperty *, int)));
- connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
- this, SLOT(slotPropertyDestroyed(QtProperty *)));
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtColorPropertyManager::~QtColorPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the manager that produces the nested \e red, \e green and
- \e blue subproperties.
- In order to provide editing widgets for the subproperties in a
- property browser widget, this manager must be associated with an
- editor factory.
- \sa QtAbstractPropertyBrowser::setFactoryForManager()
- */
- QtIntPropertyManager *QtColorPropertyManager::subIntPropertyManager() const
- {
- return d_ptr->m_intPropertyManager;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by \e this manager, this
- function returns an invalid color.
- \sa setValue()
- */
- QColor QtColorPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QColor());
- }
- /*!
- \reimp
- */
- QString QtColorPropertyManager::valueText(const QtProperty *property) const
- {
- const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return QtPropertyBrowserUtils::colorValueText(it.value());
- }
- /*!
- \reimp
- */
- QIcon QtColorPropertyManager::valueIcon(const QtProperty *property) const
- {
- const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QIcon();
- return QtPropertyBrowserUtils::brushValueIcon(QBrush(it.value()));
- }
- /*!
- \fn void QtColorPropertyManager::setValue(QtProperty *property, const QColor &value)
- Sets the value of the given \a property to \a value. Nested
- properties are updated automatically.
- \sa value(), valueChanged()
- */
- void QtColorPropertyManager::setValue(QtProperty *property, const QColor &val)
- {
- const QtColorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- if (it.value() == val)
- return;
- it.value() = val;
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToR[property], val.red());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToG[property], val.green());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToB[property], val.blue());
- d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToA[property], val.alpha());
- emit propertyChanged(property);
- emit valueChanged(property, val);
- }
- /*!
- \reimp
- */
- void QtColorPropertyManager::initializeProperty(QtProperty *property)
- {
- QColor val;
- d_ptr->m_values[property] = val;
- QtProperty *rProp = d_ptr->m_intPropertyManager->addProperty();
- rProp->setPropertyName(tr("Red"));
- d_ptr->m_intPropertyManager->setValue(rProp, val.red());
- d_ptr->m_intPropertyManager->setRange(rProp, 0, 0xFF);
- d_ptr->m_propertyToR[property] = rProp;
- d_ptr->m_rToProperty[rProp] = property;
- property->addSubProperty(rProp);
- QtProperty *gProp = d_ptr->m_intPropertyManager->addProperty();
- gProp->setPropertyName(tr("Green"));
- d_ptr->m_intPropertyManager->setValue(gProp, val.green());
- d_ptr->m_intPropertyManager->setRange(gProp, 0, 0xFF);
- d_ptr->m_propertyToG[property] = gProp;
- d_ptr->m_gToProperty[gProp] = property;
- property->addSubProperty(gProp);
- QtProperty *bProp = d_ptr->m_intPropertyManager->addProperty();
- bProp->setPropertyName(tr("Blue"));
- d_ptr->m_intPropertyManager->setValue(bProp, val.blue());
- d_ptr->m_intPropertyManager->setRange(bProp, 0, 0xFF);
- d_ptr->m_propertyToB[property] = bProp;
- d_ptr->m_bToProperty[bProp] = property;
- property->addSubProperty(bProp);
- QtProperty *aProp = d_ptr->m_intPropertyManager->addProperty();
- aProp->setPropertyName(tr("Alpha"));
- d_ptr->m_intPropertyManager->setValue(aProp, val.alpha());
- d_ptr->m_intPropertyManager->setRange(aProp, 0, 0xFF);
- d_ptr->m_propertyToA[property] = aProp;
- d_ptr->m_aToProperty[aProp] = property;
- property->addSubProperty(aProp);
- }
- /*!
- \reimp
- */
- void QtColorPropertyManager::uninitializeProperty(QtProperty *property)
- {
- QtProperty *rProp = d_ptr->m_propertyToR[property];
- if (rProp) {
- d_ptr->m_rToProperty.remove(rProp);
- delete rProp;
- }
- d_ptr->m_propertyToR.remove(property);
- QtProperty *gProp = d_ptr->m_propertyToG[property];
- if (gProp) {
- d_ptr->m_gToProperty.remove(gProp);
- delete gProp;
- }
- d_ptr->m_propertyToG.remove(property);
- QtProperty *bProp = d_ptr->m_propertyToB[property];
- if (bProp) {
- d_ptr->m_bToProperty.remove(bProp);
- delete bProp;
- }
- d_ptr->m_propertyToB.remove(property);
- QtProperty *aProp = d_ptr->m_propertyToA[property];
- if (aProp) {
- d_ptr->m_aToProperty.remove(aProp);
- delete aProp;
- }
- d_ptr->m_propertyToA.remove(property);
- d_ptr->m_values.remove(property);
- }
- // QtCursorPropertyManager
- // Make sure icons are removed as soon as QApplication is destroyed, otherwise,
- // handles are leaked on X11.
- static void clearCursorDatabase();
- namespace {
- struct CursorDatabase : public QtCursorDatabase
- {
- CursorDatabase()
- {
- qAddPostRoutine(clearCursorDatabase);
- }
- };
- }
- Q_GLOBAL_STATIC(QtCursorDatabase, cursorDatabase)
- static void clearCursorDatabase()
- {
- cursorDatabase()->clear();
- }
- class QtCursorPropertyManagerPrivate
- {
- QtCursorPropertyManager *q_ptr;
- Q_DECLARE_PUBLIC(QtCursorPropertyManager)
- public:
- typedef QMap<const QtProperty *, QCursor> PropertyValueMap;
- PropertyValueMap m_values;
- };
- /*!
- \class QtCursorPropertyManager
- \brief The QtCursorPropertyManager provides and manages QCursor properties.
- A cursor property has a current value which can be
- retrieved using the value() function, and set using the setValue()
- slot. In addition, QtCursorPropertyManager provides the
- valueChanged() signal which is emitted whenever a property created
- by this manager changes.
- \sa QtAbstractPropertyManager
- */
- /*!
- \fn void QtCursorPropertyManager::valueChanged(QtProperty *property, const QCursor &value)
- This signal is emitted whenever a property created by this manager
- changes its value, passing a pointer to the \a property and the new
- \a value as parameters.
- \sa setValue()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtCursorPropertyManager::QtCursorPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtCursorPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtCursorPropertyManager::~QtCursorPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns a default QCursor object.
- \sa setValue()
- */
- #ifndef QT_NO_CURSOR
- QCursor QtCursorPropertyManager::value(const QtProperty *property) const
- {
- return d_ptr->m_values.value(property, QCursor());
- }
- #endif
- /*!
- \reimp
- */
- QString QtCursorPropertyManager::valueText(const QtProperty *property) const
- {
- const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QString();
- return cursorDatabase()->cursorToShapeName(it.value());
- }
- /*!
- \reimp
- */
- QIcon QtCursorPropertyManager::valueIcon(const QtProperty *property) const
- {
- const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
- if (it == d_ptr->m_values.constEnd())
- return QIcon();
- return cursorDatabase()->cursorToShapeIcon(it.value());
- }
- /*!
- \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
- Sets the value of the given \a property to \a value.
- \sa value(), valueChanged()
- */
- void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
- {
- #ifndef QT_NO_CURSOR
- const QtCursorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
- if (it == d_ptr->m_values.end())
- return;
- if (it.value().shape() == value.shape() && value.shape() != Qt::BitmapCursor)
- return;
- it.value() = value;
- emit propertyChanged(property);
- emit valueChanged(property, value);
- #endif
- }
- /*!
- \reimp
- */
- void QtCursorPropertyManager::initializeProperty(QtProperty *property)
- {
- #ifndef QT_NO_CURSOR
- d_ptr->m_values[property] = QCursor();
- #endif
- }
- /*!
- \reimp
- */
- void QtCursorPropertyManager::uninitializeProperty(QtProperty *property)
- {
- d_ptr->m_values.remove(property);
- }
- #if QT_VERSION >= 0x040400
- QT_END_NAMESPACE
- #endif
- #include "moc_qtpropertymanager.cpp"
- #include "qtpropertymanager.moc"
|