Exemple #1
0
    def __update_available_rules(self):
        self.trw_qrs.setUpdatesEnabled(False)  # Don't render until we're ready

        # Grab some context data
        top_level_items_expanded_info = dict()
        for i in range(self.trw_qrs.topLevelItemCount()):
            top_level_items_expanded_info[self.trw_qrs.topLevelItem(i).text(0)] = self.trw_qrs.topLevelItem(i).isExpanded()

        # Save selection
        self.__update_selected_items()

        # Iterate qr types adding children
        self.trw_qrs.blockSignals(True)  # We don't want to get itemSelectionChanged here
        self.trw_qrs.clear()
        self.trw_qrs.blockSignals(False)

        bold_font = QFont()
        bold_font.setBold(True)

        sorted_types = sorted(self.__controller.get_qrs_tree_data().keys())
        for type_enum in sorted_types:
            children = []
            type_item = QTreeWidgetItem([self.__controller.get_tr_string(type_enum)])

            # Filter by search text
            list_qrs = self.__filter_by_search_text(type_enum, self.txt_search.text())

            for qr in list_qrs:
                qr_item = QTreeWidgetItem([qr.name()])
                qr_item.setData(0, Qt.UserRole, qr.id())
                qr_item.setData(0, Qt.ToolTipRole, "{}\n{}".format(qr.name(), qr.id()))
                children.append(qr_item)

            if children:
                icon_name = self.__icon_names[type_enum.value]
                icon = QIcon(":/Asistente-LADM-COL/resources/images/{}".format(icon_name))
                type_item.setData(0, Qt.DecorationRole, icon)
                type_item.setData(0, Qt.FontRole, bold_font)
                type_item.addChildren(children)
                self.trw_qrs.addTopLevelItem(type_item)

        # Set selection
        iterator = QTreeWidgetItemIterator(self.trw_qrs, QTreeWidgetItemIterator.Selectable)
        self.trw_qrs.blockSignals(True)  # We don't want to get itemSelectionChanged here
        while iterator.value():
            item = iterator.value()
            if item.data(0, Qt.UserRole) in self.__selected_items_list:
                item.setSelected(True)

            iterator += 1

        self.trw_qrs.blockSignals(False)

        # Make type items non selectable
        # Set expand taking previous states into account
        for i in range(self.trw_qrs.topLevelItemCount()):
            self.trw_qrs.topLevelItem(i).setFlags(Qt.ItemIsEnabled)  # Not selectable
            self.trw_qrs.topLevelItem(i).setExpanded(top_level_items_expanded_info.get(self.trw_qrs.topLevelItem(i).text(0), True))

        self.trw_qrs.setUpdatesEnabled(True)  # Now render!
 def expandEditorTree(self, connectionItem):
     iter = QTreeWidgetItemIterator(connectionItem)
     val = iter.value()
     while val:
         val.setExpanded(True)
         iter += 1
         val = iter.value()
 def selectFirstChangedFeature(self):
     iterator = QTreeWidgetItemIterator(self.featuresTree)
     while iterator.value():
         item = iterator.value()
         if isinstance(item, FeatureItem):
             self.featuresTree.setCurrentItem(item)
             return
         iterator += 1
 def update_image_items(self):
     it = QTreeWidgetItemIterator(self.tree)
     while it.value():
         item = it.value()
         if isinstance(item, SceneItem):
             w = self.tree.itemWidget(item, 0)
             w.set_metadata_to_show(self._metadata_to_show)
         it += 1
Exemple #5
0
    def accepted(self):
        #self.qgis_utils.remove_error_group_requested.emit()

        iterator = QTreeWidgetItemIterator(self.trw_quality_rules,
                                           QTreeWidgetItemIterator.Selectable)
        while iterator.value():
            item = iterator.value()

            if item.isSelected():
                id = item.data(0, Qt.UserRole)

                if id == 'check_overlaps_in_boundary_points':
                    self.quality.check_overlapping_points(
                        self._db, BOUNDARY_POINT_TABLE)
                elif id == 'check_overlaps_in_control_points':
                    self.quality.check_overlapping_points(
                        self._db, CONTROL_POINT_TABLE)
                elif id == 'check_boundary_points_covered_by_boundary_nodes':
                    self.quality.check_boundary_points_covered_by_boundary_nodes(
                        self._db)
                elif id == 'check_too_long_boundary_segments':
                    self.quality.check_too_long_segments(self._db)
                elif id == 'check_overlaps_in_boundaries':
                    self.quality.check_overlaps_in_boundaries(self._db)
                elif id == 'check_boundaries_are_not_split':
                    self.quality.check_boundaries_are_not_split(self._db)
                elif id == 'check_boundaries_covered_by_plots':
                    self.quality.check_boundaries_covered_by_plots(self._db)
                elif id == 'check_missing_boundary_points_in_boundaries':
                    self.quality.check_missing_boundary_points_in_boundaries(
                        self._db)
                elif id == 'check_dangles_in_boundaries':
                    self.quality.check_dangles_in_boundaries(self._db)
                elif id == 'check_overlaps_in_plots':
                    self.quality.check_overlapping_polygons(
                        self._db, PLOT_TABLE)
                elif id == 'check_overlaps_in_buildings':
                    self.quality.check_overlapping_polygons(
                        self._db, BUILDING_TABLE)
                elif id == 'check_overlaps_in_rights_of_way':
                    self.quality.check_overlapping_polygons(
                        self._db, RIGHT_OF_WAY_TABLE)
                elif id == 'check_plots_covered_by_boundaries':
                    self.quality.check_plots_covered_by_boundaries(self._db)
                #elif id == 'check_missing_survey_points_in_buildings':
                #    self.quality.check_missing_survey_points_in_buildings(self._db)
                elif id == 'check_right_of_way_overlaps_buildings':
                    self.quality.check_right_of_way_overlaps_buildings(
                        self._db)
                elif id == 'check_gaps_in_plots':
                    self.quality.check_gaps_in_plots(self._db)
                elif id == 'check_multipart_in_right_of_way':
                    self.quality.check_multiparts_in_right_of_way(self._db)

            iterator += 1

        if self.qgis_utils.error_group_exists():
            self.qgis_utils.set_error_group_visibility(True)
Exemple #6
0
 def autoSelectFirstConflict(self):
     iterator = QTreeWidgetItemIterator(self.conflictsTree)
     while iterator.value():
         item = iterator.value()
         if isinstance(item, ConflictItem):
             self.conflictsTree.setCurrentItem(item)
             self.treeItemClicked()
             return
         iterator += 1
 def okPressed(self):
     self.tests = []
     iterator = QTreeWidgetItemIterator(self.testsTree)
     item = iterator.value()
     while item:
         if item.checkState(0) == Qt.Checked and item.childCount() == 0:
             self.tests.append(item.test)
         iterator +=1
         item = iterator.value()
     self.close()
Exemple #8
0
 def okPressed(self):
     self.tests = []
     iterator = QTreeWidgetItemIterator(self.testsTree)
     item = iterator.value()
     while item:
         if item.checkState(0) == Qt.Checked and item.childCount() == 0:
             self.tests.append(item.test)
         iterator += 1
         item = iterator.value()
     self.close()
Exemple #9
0
    def accepted(self):
        # we erase the group error layer every time it runs because we assume that data set changes.
        self.app.gui.remove_error_group()

        iterator = QTreeWidgetItemIterator(self.trw_quality_rules, QTreeWidgetItemIterator.Selectable)
        while iterator.value():
            item = iterator.value()
            if item.isSelected():
                self.selected_rules[item.data(0, Qt.UserRole)] = item.text(0)  # rule_key: rule_name
            iterator += 1
Exemple #10
0
    def get_items(self, flags=QTreeWidgetItemIterator.All):
        """ Returns an iterator over the tree items. """

        # noinspection PyTypeChecker
        twit = QTreeWidgetItemIterator(self.tree_products, flags)

        while twit.value(
        ) is not None:  #This 'orrible iteration style offends me greatly
            yield twit.value()
            twit += 1
Exemple #11
0
    def __get_item_by_qr_key(self, qr_key):
        iterator = QTreeWidgetItemIterator(self.trw_qrs,
                                           QTreeWidgetItemIterator.Selectable)
        while iterator.value():
            item = iterator.value()
            if item.data(QR_COLUMN, Qt.UserRole) == qr_key:
                return item

            iterator += 1

        return None
 def selected_images(self):
     selected = []
     it = QTreeWidgetItemIterator(self.tree)
     while it.value():
         item = it.value()
         if isinstance(item, SceneItem):
             w = self.tree.itemWidget(item, 0)
             w.set_metadata_to_show(self._metadata_to_show)
             if w.is_selected():
                 selected.append(w.image)
         it += 1
     return selected
Exemple #13
0
    def toggleRunButton(self):
        self.tests = []
        iterator = QTreeWidgetItemIterator(self.testsTree)
        item = iterator.value()
        while item:
            if item.checkState(0) == Qt.Checked and item.childCount() == 0:
                self.tests.append(item.test)
            iterator += 1
            item = iterator.value()

        self.buttonBox.button(
            QDialogButtonBox.Ok).setEnabled(len(self.tests) > 0)
Exemple #14
0
 def saveValues():
     iterator = QTreeWidgetItemIterator(self.tree)
     value = iterator.value()
     while value:
         if hasattr(value, 'saveValue'):
             try:
                 value.saveValue()
             except WrongValueException:
                 return
         iterator += 1
         value = iterator.value()
     QDialog.accept(self)
     self.close()
Exemple #15
0
    def __update_selected_item(self):
        self.__selected_item = None
        iterator = QTreeWidgetItemIterator(self.trw_qrs,
                                           QTreeWidgetItemIterator.Selectable)
        while iterator.value():
            item = iterator.value()
            qr_key = item.data(QR_COLUMN, Qt.UserRole)

            if item.isSelected():
                self.__selected_item = qr_key
                break

            iterator += 1
Exemple #16
0
    def update_selected_items(self):
        iterator = QTreeWidgetItemIterator(self.trw_layers, QTreeWidgetItemIterator.Selectable)
        while iterator.value():
            item = iterator.value()

            if item.isSelected():
                self.selected_items_dict[item.text(0)] = item.data(0, Qt.UserRole)
            else:
                if item.text(0) in self.selected_items_dict:
                    # It was selected before, but not anymore
                    del self.selected_items_dict[item.text(0)]

            iterator += 1
 def saveSettings(self):
     iterator = QTreeWidgetItemIterator(self.tree)
     value = iterator.value()
     while value:
         if hasattr(value, 'saveValue'):
             try:
                 value.saveValue()
             except Exception as e:
                 self.bar.pushMessage("Error for parameter '%s':" % value.param.description,
                                      str(e), level=QgsMessageBar.WARNING)
                 return False
         iterator += 1
         value = iterator.value()
     return True
Exemple #18
0
    def __update_selected_items(self):
        iterator = QTreeWidgetItemIterator(self.trw_qrs, QTreeWidgetItemIterator.Selectable)
        while iterator.value():
            item = iterator.value()
            qr_key = item.data(0, Qt.UserRole)

            if item.isSelected():
                if qr_key not in self.__selected_items_list:
                    self.__selected_items_list.append(qr_key)
            else:
                if qr_key in self.__selected_items_list:
                    # It was selected before, but not anymore
                    self.__selected_items_list.remove(qr_key)

            iterator += 1

        self.__update_controls_after_selection_update()
Exemple #19
0
    def select_predefined_changed(self, index):
        layer_list = self.cbo_select_predefined_tables.currentData()

        # Clear layer selection
        self.trw_layers.blockSignals(
            True)  # We don't want to get itemSelectionChanged here
        self.trw_layers.clearSelection()
        self.trw_layers.blockSignals(False)
        self.selected_items_dict = dict()

        # First find corresponding unique names in tree, since for
        # tables with multiple geometry columns, the tree has as much
        # tables as geometry columns are, but the table name is the same
        select_layers_list = list()
        for model, tables in self.models_tree.items():
            for table_name_in_tree, record in tables.items():
                if record[QueryNames.TABLE_NAME_MODEL_BAKER] in layer_list:
                    select_layers_list.append(table_name_in_tree)
                    self.selected_items_dict[table_name_in_tree] = record

        self.update_selected_count_label()

        # Select predefined layers in the view (some layers might not be visible)
        if select_layers_list:
            self.trw_layers.blockSignals(
                True)  # We don't want to get itemSelectionChanged here
            count = len(
                select_layers_list)  # We can stop before iterating all layers
            iterator = QTreeWidgetItemIterator(
                self.trw_layers, QTreeWidgetItemIterator.Selectable)
            while iterator.value():
                item = iterator.value()
                if item.text(0) in select_layers_list:
                    item.setSelected(True)
                    count -= 1
                    if count == 0:
                        break

                iterator += 1

            self.trw_layers.blockSignals(False)
    def accept(self):
        iterator = QTreeWidgetItemIterator(self.tree)
        value = iterator.value()
        while value:
            if hasattr(value, 'checkValue'):
                if value.checkValue():
                    value.setBackgroundColor(1, Qt.white)
                else:
                    value.setBackgroundColor(1, Qt.yellow)
                    return

            iterator += 1
            value = iterator.value()
        iterator = QTreeWidgetItemIterator(self.tree)
        value = iterator.value()
        while value:
            if hasattr(value, 'saveValue'):
                value.saveValue()
            iterator += 1
            value = iterator.value()
        QDialog.accept(self)
    def filter_by_text(self, searchtext):
        # no text filter
        if searchtext == '':
            # folds all folders
            self.collapseAll()
            # show all items
            it = QTreeWidgetItemIterator(self)
            while it.value():
                item = it.value()
                item.setHidden(False)
                it += 1
                # text filter

        # if no filter is set, folds all items
        else:
            # hide all items
            it = QTreeWidgetItemIterator(self)
            while it.value():
                item = it.value()
                item.setHidden(True)
                it += 1
            # iterate through all items
            it = QTreeWidgetItemIterator(self)
            while it.value():
                item = it.value()
                # if text is found in item
                if searchtext.lower() in item.text(0).lower():
                    # make this item visible
                    item.setHidden(False)
                    # make its parent visibles
                    self.show_parents(item)
                    # make its children visible
                    self.show_children(item)
                it += 1
            # unfold all folders
            self.expandAll()
    def accepted(self):
        # we erase the group error layer every time it runs because we assume that data set changes.
        self.qgis_utils.remove_error_group_requested.emit()
        self.quality.initialize_log_dialog_quality()
        self.quality.set_count_topology_rules(
            len(self.trw_quality_rules.selectedItems()))

        iterator = QTreeWidgetItemIterator(self.trw_quality_rules,
                                           QTreeWidgetItemIterator.Selectable)
        while iterator.value():
            item = iterator.value()

            if item.isSelected():
                id = item.data(0, Qt.UserRole)
                rule_name = item.text(0)

                if id == 'check_overlaps_in_boundary_points':
                    self.quality.check_overlapping_points(
                        self._db,
                        point_layer_name=BOUNDARY_POINT_TABLE,
                        rule_name=rule_name)
                elif id == 'check_overlaps_in_control_points':
                    self.quality.check_overlapping_points(
                        self._db,
                        point_layer_name=CONTROL_POINT_TABLE,
                        rule_name=rule_name)
                elif id == 'check_boundary_points_covered_by_boundary_nodes':
                    self.quality.check_boundary_points_covered_by_boundary_nodes(
                        self._db, rule_name=rule_name)
                elif id == 'check_boundary_points_covered_by_plot_nodes':
                    self.quality.check_boundary_points_covered_by_plot_nodes(
                        self._db, rule_name=rule_name)
                elif id == 'check_too_long_boundary_segments':
                    self.quality.check_too_long_segments(self._db,
                                                         rule_name=rule_name)
                elif id == 'check_overlaps_in_boundaries':
                    self.quality.check_overlaps_in_boundaries(
                        self._db, rule_name=rule_name)
                elif id == 'check_boundaries_are_not_split':
                    self.quality.check_boundaries_are_not_split(
                        self._db, rule_name=rule_name)
                elif id == 'check_boundaries_covered_by_plots':
                    self.quality.check_boundaries_covered_by_plots(
                        self._db, rule_name=rule_name)
                elif id == 'check_boundary_nodes_covered_by_boundary_points':
                    self.quality.check_boundary_nodes_covered_by_boundary_points(
                        self._db, rule_name=rule_name)
                elif id == 'check_dangles_in_boundaries':
                    self.quality.check_dangles_in_boundaries(
                        self._db, rule_name=rule_name)
                elif id == 'check_overlaps_in_plots':
                    self.quality.check_overlapping_polygons(
                        self._db,
                        polygon_layer_name=PLOT_TABLE,
                        rule_name=rule_name)
                elif id == 'check_overlaps_in_buildings':
                    self.quality.check_overlapping_polygons(
                        self._db,
                        polygon_layer_name=BUILDING_TABLE,
                        rule_name=rule_name)
                elif id == 'check_overlaps_in_rights_of_way':
                    self.quality.check_overlapping_polygons(
                        self._db,
                        polygon_layer_name=RIGHT_OF_WAY_TABLE,
                        rule_name=rule_name)
                elif id == 'check_plots_covered_by_boundaries':
                    self.quality.check_plots_covered_by_boundaries(
                        self._db, rule_name=rule_name)
                #elif id == 'check_missing_survey_points_in_buildings':
                #    self.quality.check_missing_survey_points_in_buildings(self._db)
                elif id == 'check_right_of_way_overlaps_buildings':
                    self.quality.check_right_of_way_overlaps_buildings(
                        self._db, rule_name=rule_name)
                elif id == 'check_gaps_in_plots':
                    self.quality.check_gaps_in_plots(self._db,
                                                     rule_name=rule_name)
                elif id == 'check_multipart_in_right_of_way':
                    self.quality.check_multiparts_in_right_of_way(
                        self._db, rule_name=rule_name)
                elif id == 'check_plot_nodes_covered_by_boundary_points':
                    self.quality.check_plot_nodes_covered_by_boundary_points(
                        self._db, rule_name=rule_name)
                elif id == 'check_buildings_should_be_within_plots':
                    self.quality.check_building_within_plots(
                        self._db, rule_name=rule_name)
                elif id == 'check_building_units_should_be_within_plots':
                    self.quality.check_building_unit_within_plots(
                        self._db, rule_name=rule_name)
                elif id == 'check_parcel_right_relationship':
                    self.quality.check_parcel_right_relationship(
                        self._db, rule_name=rule_name)
                elif id == 'find_duplicate_records_in_a_table':
                    self.quality.find_duplicate_records_in_a_table(
                        self._db, rule_name=rule_name)
                elif id == 'check_fraction_sum_for_party_groups':
                    self.quality.check_fraction_sum_for_party_groups(
                        self._db, rule_name=rule_name)
                elif id == 'check_department_code_has_two_numerical_characters':
                    self.quality.basic_logic_validations(
                        self._db,
                        rule='DEPARTMENT_CODE_VALIDATION',
                        rule_name=rule_name)
                elif id == 'check_municipality_code_has_three_numerical_characters':
                    self.quality.basic_logic_validations(
                        self._db,
                        rule='MUNICIPALITY_CODE_VALIDATION',
                        rule_name=rule_name)
                elif id == 'check_zone_code_has_two_numerical_characters':
                    self.quality.basic_logic_validations(
                        self._db,
                        rule='ZONE_CODE_VALIDATION',
                        rule_name=rule_name)
                elif id == 'check_parcel_number_has_30_numerical_characters':
                    self.quality.basic_logic_validations(
                        self._db,
                        rule='PARCEL_NUMBER_VALIDATION',
                        rule_name=rule_name)
                elif id == 'check_parcel_number_before_has_20_numerical_characters':
                    self.quality.basic_logic_validations(
                        self._db,
                        rule='PARCEL_NUMBER_BEFORE_VALIDATION',
                        rule_name=rule_name)
                elif id == 'check_col_party_natural_type':
                    self.quality.advanced_logic_validations(
                        self._db,
                        rule='COL_PARTY_TYPE_NATURAL_VALIDATION',
                        rule_name=rule_name)
                elif id == 'check_col_party_legal_type':
                    self.quality.advanced_logic_validations(
                        self._db,
                        rule='COL_PARTY_TYPE_NO_NATURAL_VALIDATION',
                        rule_name=rule_name)
                elif id == 'check_parcel_type_and_22_position_of_parcel_number':
                    self.quality.advanced_logic_validations(
                        self._db,
                        rule=
                        'PARCEL_TYPE_AND_22_POSITION_OF_PARCEL_NUMBER_VALIDATION',
                        rule_name=rule_name)
                elif id == 'check_uebaunit_parcel':
                    self.quality.advanced_logic_validations(
                        self._db,
                        rule='UEBAUNIT_PARCEL_VALIDATION',
                        rule_name=rule_name)

            iterator += 1

        self.quality.generate_log_button()

        if self.qgis_utils.error_group_exists():
            group = self.qgis_utils.get_error_layers_group()
            # # Check if group layer is empty
            if group.findLayers():
                self.qgis_utils.set_error_group_visibility(True)
            else:
                self.qgis_utils.remove_error_group_requested.emit()
Exemple #23
0
    def update_available_layers(self):
        self.trw_layers.setUpdatesEnabled(
            False)  # Don't render until we're ready

        # Grab some context data
        show_domains = self.chk_show_domains.isChecked()
        show_structures = self.chk_show_structures.isChecked()
        show_associations = self.chk_show_associations.isChecked()
        top_level_items_expanded_info = []
        for i in range(self.trw_layers.topLevelItemCount()):
            top_level_items_expanded_info.append(
                self.trw_layers.topLevelItem(i).isExpanded())

        # Save selection
        self.update_selected_items()

        # Iterate models adding children
        self.trw_layers.blockSignals(
            True)  # We don't want to get itemSelectionChanged here
        self.trw_layers.clear()
        self.trw_layers.blockSignals(False)

        sorted_models = sorted(self.models_tree.keys())
        for model in sorted_models:
            children = []
            model_item = QTreeWidgetItem([model])

            # Filter by search text
            list_tables = self.filter_tables_by_search_text(
                self.models_tree[model].keys(), self.txt_search_text.text())
            sorted_tables = sorted(list_tables)

            for table in sorted_tables:
                current_table_info = self.models_tree[model][table]
                if current_table_info[QueryNames.KIND_SETTINGS_MODEL_BAKER] == ILI2DBNames.TABLE_PROP_DOMAIN and not show_domains \
                   or current_table_info[QueryNames.KIND_SETTINGS_MODEL_BAKER] == ILI2DBNames.TABLE_PROP_STRUCTURE and not show_structures \
                   or current_table_info[QueryNames.KIND_SETTINGS_MODEL_BAKER] == ILI2DBNames.TABLE_PROP_ASSOCIATION and not show_associations:
                    continue

                table_item = QTreeWidgetItem([table])
                table_item.setData(0, Qt.UserRole,
                                   self.models_tree[model][table])
                geometry_type = QgsWkbTypes().geometryType(
                    QgsWkbTypes().parseType(current_table_info[
                        QueryNames.GEOMETRY_TYPE_MODEL_BAKER])
                ) if current_table_info[
                    QueryNames.GEOMETRY_TYPE_MODEL_BAKER] else None
                icon_name = self.icon_names[
                    3 if geometry_type is None else geometry_type]

                # Is the layer already loaded in canvas?
                if self.app.core.get_ladm_layer_from_qgis(
                        self._db,
                        current_table_info[QueryNames.TABLE_NAME_MODEL_BAKER],
                        EnumLayerRegistryType.IN_LAYER_TREE) is not None:
                    table_item.setText(
                        0, table + QCoreApplication.translate(
                            "LoadLayersDialog", " [already loaded]"))
                    table_item.setData(0, Qt.ForegroundRole,
                                       QBrush(Qt.lightGray))
                    table_item.setFlags(Qt.ItemIsEnabled)  # Not selectable
                else:  # Laye not in QGIS Layer Tree
                    if not current_table_info[
                            QueryNames.
                            KIND_SETTINGS_MODEL_BAKER]:  # This is a class
                        font = QFont()
                        font.setBold(True)
                        table_item.setData(0, Qt.FontRole, font)

                if current_table_info[
                        QueryNames.
                        KIND_SETTINGS_MODEL_BAKER] == ILI2DBNames.TABLE_PROP_DOMAIN:
                    icon_name = self.icon_names[4]
                elif current_table_info[
                        QueryNames.
                        KIND_SETTINGS_MODEL_BAKER] == ILI2DBNames.TABLE_PROP_STRUCTURE:
                    if geometry_type is None:
                        icon_name = self.icon_names[5]
                elif current_table_info[
                        QueryNames.
                        KIND_SETTINGS_MODEL_BAKER] == ILI2DBNames.TABLE_PROP_ASSOCIATION:
                    icon_name = self.icon_names[6]
                icon = QIcon(":/Asistente-LADM-COL/resources/images/{}".format(
                    icon_name))
                table_item.setData(0, Qt.DecorationRole, icon)

                children.append(table_item)

            model_item.addChildren(children)
            self.trw_layers.addTopLevelItem(model_item)

        # Set selection
        iterator = QTreeWidgetItemIterator(self.trw_layers,
                                           QTreeWidgetItemIterator.Selectable)
        self.trw_layers.blockSignals(
            True)  # We don't want to get itemSelectionChanged here
        while iterator.value():
            item = iterator.value()
            if item.text(0) in self.selected_items_dict:
                item.setSelected(True)

            iterator += 1

        self.trw_layers.blockSignals(False)

        # Make model items non selectable
        # Set expand taking previous states into account
        for i in range(self.trw_layers.topLevelItemCount()):
            self.trw_layers.topLevelItem(i).setFlags(
                Qt.ItemIsEnabled)  # Not selectable
            self.trw_layers.topLevelItem(i).setExpanded(
                top_level_items_expanded_info[i]
                if top_level_items_expanded_info else True)

        self.trw_layers.setUpdatesEnabled(True)  # Now render!