Пример #1
0
 private function createRootItemWidget($property, $object, $tree, $itemIndex)
 {
     $widget = null;
     switch ($property['type']) {
         case 'mixed':
         case 'int':
             $widget = new QLineEdit();
             if (isset($property['value']) && !$defaultPropertiesLoaded) {
                 $widget->text = $property['value'];
             } else {
                 $widget->text = $object->{$property}['property'];
             }
             // set validator if section exists
             if (isset($property['validator'])) {
                 $widget->setRegExpValidator($property['validator']);
             } else {
                 // if property type is `int` and validator section not exists,
                 // then set a default validator for integers
                 if ($property['type'] == 'int') {
                     $widget->setRegExpValidator('[0-9]*');
                 }
             }
             $widget->connect(SIGNAL('textChanged(QString)'), $this, SLOT('setObjectProperty(QString)'));
             break;
         case 'bool':
             $widget = new QCheckBox();
             if (isset($property['value']) && !$defaultPropertiesLoaded) {
                 $widget->checked = $property['value'];
             } else {
                 $widget->checked = $object->{$property}['property'];
             }
             $widget->connect(SIGNAL('toggled(bool)'), $this, SLOT('setObjectProperty(bool)'));
             break;
         case 'combo-list':
             foreach ($property['list'] as $listItemProperty) {
                 $childItemIndex = $tree->addItem($itemIndex, $listItemProperty['title']);
                 $childItemWidget = $this->createRootItemWidget($listItemProperty, $object, $tree, $itemIndex);
                 if ($childItemWidget != null) {
                     $childItemWidget->__pq_property_ = $property['property'];
                     $childItemWidget->__pq_propertyType_ = $property['type'];
                     $childItemWidget->objectName = "__pq_property_combo_" . $property['property'] . "_" . $listItemProperty['property'];
                     $tree->setItemWidget($childItemIndex, 1, $childItemWidget);
                 }
             }
             break;
         case 'combo':
             $widget = new QComboBox();
             if (isset($property['list']) && is_array($property['list'])) {
                 $index = 0;
                 foreach ($property['list'] as $list) {
                     if (isset($list['title']) && isset($list['value'])) {
                         $cPropertyValue = "cPropertyValue_{$index}";
                         $qvalue = "__pq_property_qvalue_{$index}";
                         $widget->addItem($list['title']);
                         $widget->{$cPropertyValue} = $list['value'];
                         $widget->{$qvalue} = $list['qvalue'];
                         if (isset($property['defaultIndex'])) {
                             $widget->currentIndex = $property['defaultIndex'];
                         }
                         $index++;
                     }
                 }
             }
             $widget->connect(SIGNAL('currentIndexChanged(int)'), $this, SLOT('setObjectProperty(int)'));
             break;
     }
     return $widget;
 }