unsafe fn load_data(&self, data: &HashMap<String, String>) -> Result<()> {

        // The listView of the variant editor is supposed to represent all the different faction versions of each variant.
        for (_, value) in data.iter()
            .sorted_by_key(|x| x.0)
            .filter(|x| x.0.starts_with(VARIANT_KEY_VALUE)) {

            // If no variant is set, use a * to identify it.
            let value = if value.is_empty() { "*" } else { value };
            let item = QStandardItem::from_q_string(&QString::from_std_str(&value)).into_ptr();

            // Search on the unit data for this faction's data, and for the definitions.
            let faction_data = data.iter()
                .filter(|x| x.0.ends_with(value) || x.0.ends_with("_definition"))
                .map(|x| {

                    // If a definition is found, insert it.
                    if x.0.ends_with("_definition") {
                        (x.0.to_owned(), x.1.to_owned())
                    }

                    // If a field belonging to our faction (value) is found, format it so we get its individual column name, without extra data.
                    else {
                        let mut clean_key = x.0.to_owned();
                        if let Some(index) = clean_key.find(value) {
                            clean_key = clean_key.split_at(index - 1).0.to_owned();
                        }
                        (clean_key, x.1.to_owned())
                    }
                })
                .collect::<HashMap<String, String>>();

            // Then, load the faction data to the UI.
            item.set_data_2a(&QVariant::from_q_string(&QString::from_std_str(&serde_json::to_string(&faction_data).unwrap())), UNIT_DATA);
            self.faction_list_model.append_row_q_standard_item(item);
        }

        self.get_unit_variants_colours_data(data)?;

        // Load icon and variantmesh paths.
        self.load_icon_paths()?;
        self.load_variant_mesh_paths()?;

        Ok(())
    }
/// This function loads the data we need for the editor to the view, inside items in the ListView.
///
/// As key we use the faction column, using * as a replacement for empty faction.
This function loads the data we need for the editor to the view, inside items in the ListView.
As key we use the faction column, using * as a replacement for empty faction.
This function loads the data we need for the editor to the view inside items in the ListView . As key we use the faction column using * as a replacement for empty faction .
unsafe fn load_data(&self, data: &HashMap<String, String>) -> Result<()> {
        // The listView of the variant editor is supposed to represent all the different faction versions of each variant.
        for (_, value) in data.iter()
            .sorted_by_key(|x| x.0)
            .filter(|x| x.0.starts_with(VARIANT_KEY_VALUE)) {
            // If no variant is set, use a * to identify it.
            let value = if value.is_empty() { "*" } else { value };
            let item = QStandardItem::from_q_string(&QString::from_std_str(&value)).into_ptr();
            // Search on the unit data for this faction's data, and for the definitions.
            let faction_data = data.iter()
                .filter(|x| x.0.ends_with(value) || x.0.ends_with("_definition"))
                .map(|x| {
                    // If a definition is found, insert it.
                    if x.0.ends_with("_definition") {
                        (x.0.to_owned(), x.1.to_owned())
                    }
                    // If a field belonging to our faction (value) is found, format it so we get its individual column name, without extra data.
                    else {
                        let mut clean_key = x.0.to_owned();
                        if let Some(index) = clean_key.find(value) {
                            clean_key = clean_key.split_at(index - 1).0.to_owned();
                        }
                        (clean_key, x.1.to_owned())
                    }
                })
                .collect::<HashMap<String, String>>();
            // Then, load the faction data to the UI.
            item.set_data_2a(&QVariant::from_q_string(&QString::from_std_str(&serde_json::to_string(&faction_data).unwrap())), UNIT_DATA);
            self.faction_list_model.append_row_q_standard_item(item);
        }
        self.get_unit_variants_colours_data(data)?;
        // Load icon and variantmesh paths.
        self.load_icon_paths()?;
        self.load_variant_mesh_paths()?;
        Ok(())
    }
unsafe fn load_data ( & self , data : & HashMap < String , String > ) -> Result < ( ) > { // The listView of the variant editor is supposed to represent all the different faction versions of each variant. for ( _ , value ) in data . iter ( ) . sorted_by_key ( | x | x . 0 ) . filter ( | x | x . 0 . starts_with ( VARIANT_KEY_VALUE ) ) { // If no variant is set, use a * to identify it. let value = if value . is_empty ( ) { " " } else { value } ; let item = QStandardItem :: from_q_string ( & QString :: from_std_str ( & value ) ) . into_ptr ( ) ; // Search on the unit data for this faction's data, and for the definitions. let faction_data = data . iter ( ) . filter ( | x | x . 0 . ends_with ( value ) || x . 0 . ends_with ( " " ) ) . map ( | x | { // If a definition is found, insert it. if x . 0 . ends_with ( " " ) { ( x . 0 . to_owned ( ) , x . 1 . to_owned ( ) ) } // If a field belonging to our faction (value) is found, format it so we get its individual column name, without extra data. else { let mut clean_key = x . 0 . to_owned ( ) ; if let Some ( index ) = clean_key . find ( value ) { clean_key = clean_key . split_at ( index - 1 ) . 0 . to_owned ( ) ; } ( clean_key , x . 1 . to_owned ( ) ) } } ) . collect :: < HashMap < String , String > > ( ) ; // Then, load the faction data to the UI. item . set_data_2a ( & QVariant :: from_q_string ( & QString :: from_std_str ( & serde_json :: to_string ( & faction_data ) . unwrap ( ) ) ) , UNIT_DATA ) ; self . faction_list_model . append_row_q_standard_item ( item ) ; } self . get_unit_variants_colours_data ( data ) ? ; // Load icon and variantmesh paths. self . load_icon_paths ( ) ? ; self . load_variant_mesh_paths ( ) ? ; Ok ( ( ) ) }
This function loads the data we need for the editor to the view, inside items in the ListView.
This function loads the data we need for the editor to the view inside items in the ListView .
&self
data
&HashMap<String, String>
&self
data
&HashMap<String, String>