@@ -1390,66 +1390,39 @@ private function getCheckBoxFieldsForLayer($layerId)
13901390 {
13911391 $ checkBoxFields = array ();
13921392
1393- try {
1394- $ qgisPath = $ this ->project ->getQgisPath ();
1395- if (!$ qgisPath || !file_exists ($ qgisPath )) {
1396- return $ checkBoxFields ;
1397- }
1398- $ projectInfo = Qgis \ProjectInfo::fromQgisPath ($ qgisPath );
1399- } catch (\Exception $ e ) {
1393+ $ qgisPath = $ this ->project ->getQgisPath ();
1394+ if (!$ qgisPath || !file_exists ($ qgisPath )) {
14001395 return $ checkBoxFields ;
14011396 }
14021397
14031398 try {
1404- $ projectLayers = $ projectInfo -> projectlayers ;
1399+ $ projectInfo = Qgis \ProjectInfo:: fromQgisPath ( $ qgisPath ) ;
14051400 } catch (\Exception $ e ) {
14061401 return $ checkBoxFields ;
14071402 }
1408- if (!is_array ($ projectLayers )) {
1403+
1404+ $ xmlLayer = $ projectInfo ->getLayerById ($ layerId );
1405+ if (!$ xmlLayer instanceof Qgis \Layer \VectorLayer) {
14091406 return $ checkBoxFields ;
14101407 }
14111408
1412- foreach ($ projectLayers as $ xmlLayer ) {
1413- if (!($ xmlLayer instanceof Qgis \Layer \VectorLayer)) {
1409+ foreach ($ xmlLayer ->fieldConfiguration as $ field ) {
1410+ $ editWidget = $ field ->editWidget ;
1411+ if (strtolower ($ editWidget ->type ) !== 'checkbox ' ) {
14141412 continue ;
14151413 }
1416- try {
1417- if ($ xmlLayer ->id !== $ layerId ) {
1418- continue ;
1419- }
1420- $ fieldConfig = $ xmlLayer ->fieldConfiguration ;
1421- } catch (\Exception $ e ) {
1414+ $ config = $ editWidget ->config ;
1415+ if (!$ config instanceof Qgis \BaseQgisObject) {
14221416 continue ;
14231417 }
1424- if (!is_array ($ fieldConfig )) {
1425- break ;
1426- }
1427- foreach ($ fieldConfig as $ field ) {
1428- try {
1429- if (!isset ($ field ->editWidget ) || !is_string ($ field ->editWidget ->type ) || strtolower ($ field ->editWidget ->type ) !== 'checkbox ' ) {
1430- continue ;
1431- }
1432- $ config = $ field ->editWidget ->config ;
1433- } catch (\Exception $ e ) {
1434- continue ;
1435- }
1436- if ($ config instanceof Qgis \BaseQgisObject) {
1437- $ data = $ config ->getData ();
1438- } elseif (is_array ($ config )) {
1439- $ data = $ config ;
1440- } else {
1441- continue ;
1442- }
1443- $ checked = array_key_exists ('CheckedState ' , $ data ) ? (string ) $ data ['CheckedState ' ] : '' ;
1444- $ unchecked = array_key_exists ('UncheckedState ' , $ data ) ? (string ) $ data ['UncheckedState ' ] : '' ;
1445- // Fall back to QGIS defaults (see QgisFormControl::fillCheckboxValues)
1446- $ checkBoxFields [(string ) $ field ->name ] = array (
1447- 'CheckedState ' => $ checked === '' ? 't ' : $ checked ,
1448- 'UncheckedState ' => $ unchecked === '' ? 'f ' : $ unchecked ,
1449- );
1450- }
1451-
1452- break ;
1418+ $ data = $ config ->getData ();
1419+ $ checked = array_key_exists ('CheckedState ' , $ data ) ? (string ) $ data ['CheckedState ' ] : '' ;
1420+ $ unchecked = array_key_exists ('UncheckedState ' , $ data ) ? (string ) $ data ['UncheckedState ' ] : '' ;
1421+ // Fall back to QGIS defaults (see QgisFormControl::fillCheckboxValues)
1422+ $ checkBoxFields [(string ) $ field ->name ] = array (
1423+ 'CheckedState ' => $ checked === '' ? 't ' : $ checked ,
1424+ 'UncheckedState ' => $ unchecked === '' ? 'f ' : $ unchecked ,
1425+ );
14531426 }
14541427
14551428 return $ checkBoxFields ;
0 commit comments