unsafe fn load_data(&self) -> Result<()> {

        // Note: this data is HashMap<DataSource, HashMap<Path, PackedFile>>.
        let receiver = CENTRAL_COMMAND.send_background(Command::GetPackedFilesFromAllSources(self.tool.used_paths.to_vec()));
        let response = CentralCommand::recv(&receiver);
        let mut data = if let Response::HashMapDataSourceHashMapVecStringPackedFile(data) = response { data } else { panic!("{}{:?}", THREADS_COMMUNICATION_ERROR, response); };

        let mut processed_data = HashMap::new();

        // Get the table's data.
        get_data_from_all_sources!(self, get_faction_data, data, processed_data, true);

        if self.tool.get_ref_used_paths().contains(&PathType::Folder(vec!["db".to_owned(), "faction_banners_tables".to_owned()])) {
            get_data_from_all_sources!(self, get_faction_banner_data, data, processed_data, true);
        }
        if self.tool.get_ref_used_paths().contains(&PathType::Folder(vec!["db".to_owned(), "faction_uniform_colours_tables".to_owned()])) {
            get_data_from_all_sources!(self, get_faction_uniform_data, data, processed_data, true);
        }

        // Finally, grab the flag files. For that, get the paths from each faction's data, and request the flag icons.
        // These flag paths are already pre-processed to contain their full icon path, and a common slash format.
        let paths_to_use = processed_data.values()
            .map(|x| x.get("flags_path").unwrap()
                .split('/')
                .map(|x| x.to_owned())
                .collect::<Vec<String>>()
            )
            .filter_map(|x| if !x.is_empty() { Some(PathType::File(x.to_vec())) } else { None })
            .collect::<Vec<PathType>>();

        let receiver = CENTRAL_COMMAND.send_background(Command::GetPackedFilesFromAllSources(paths_to_use));
        let response = CentralCommand::recv(&receiver);
        let images_data = if let Response::HashMapDataSourceHashMapVecStringPackedFile(data) = response { data } else { panic!("{}{:?}", THREADS_COMMUNICATION_ERROR, response); };

        // Map the paths to be a single string, lowercase. That should speed-up things.
        let images_data: HashMap<DataSource, HashMap<String, PackedFile>> = images_data.iter().map(|(x, y)| (*x, y.par_iter().map(|(path, z)| (path.join("/").to_lowercase(), z.clone())).collect())).collect();

        // Once we got everything processed, build the items for the ListView.
        for (key, data) in processed_data.iter().sorted_by_key(|x| x.0) {

            let item = QStandardItem::from_q_string(&QString::from_std_str(&format!("{} - {}", data.get("screen_name").unwrap(), key))).into_ptr();
            item.set_data_2a(&QVariant::from_q_string(&QString::from_std_str(&serde_json::to_string(data).unwrap())), FACTION_DATA);

            // Image paths, we may or may not have them, so only try to load them if we actually have a path for them.
            if let Some(image_path) = data.get("flags_path") {
                let image_path_lowercase = image_path.to_lowercase();
                let mut image_data = None;

                if let Some(data) = images_data.get(&DataSource::PackFile) {
                    if let Some(image_packed_file) = data.get(&image_path_lowercase) {
                        image_data = Some(image_packed_file.get_raw_data().unwrap());
                    }
                }
                if image_data.is_none() {
                    if let Some(data) = images_data.get(&DataSource::ParentFiles) {
                        if let Some(image_packed_file) = data.get(&image_path_lowercase) {
                            image_data = Some(image_packed_file.get_raw_data().unwrap());
                        }
                    }
                }
                if image_data.is_none() {
                    if let Some(data) = images_data.get(&DataSource::GameFiles) {
                        if let Some(image_packed_file) = data.get(&image_path_lowercase) {
                            image_data = Some(image_packed_file.get_raw_data().unwrap());
                        }
                    }
                }

                // If we got an image, load it into an icon, and load its raw data into the item, for future use.
                if let Some(image_data) = image_data {
                    let byte_array = QByteArray::from_slice(&image_data);
                    let image = QPixmap::new();
                    image.load_from_data_q_byte_array(&byte_array);
                    item.set_icon(&QIcon::from_q_pixmap(&image));

                    // Store the icon for future use.
                    item.set_data_2a(&QVariant::from_q_byte_array(&byte_array), FACTION_ICON);
                }
            }

            // Finally, add the item to the list.
            self.faction_list_model.append_row_q_standard_item(item);
        }

        // Store the PackedFiles for use when saving.
        *self.tool.packed_files.borrow_mut() = data;
        Ok(())
    }
/// This function loads the data we need for the faction painter to the view, inside items in the ListView.
This function loads the data we need for the faction painter to the view, inside items in the ListView.
This function loads the data we need for the faction painter to the view inside items in the ListView .
unsafe fn load_data(&self) -> Result<()> {
        // Note: this data is HashMap<DataSource, HashMap<Path, PackedFile>>.
        let receiver = CENTRAL_COMMAND.send_background(Command::GetPackedFilesFromAllSources(self.tool.used_paths.to_vec()));
        let response = CentralCommand::recv(&receiver);
        let mut data = if let Response::HashMapDataSourceHashMapVecStringPackedFile(data) = response { data } else { panic!("{}{:?}", THREADS_COMMUNICATION_ERROR, response); };
        let mut processed_data = HashMap::new();
        // Get the table's data.
        get_data_from_all_sources!(self, get_faction_data, data, processed_data, true);
        if self.tool.get_ref_used_paths().contains(&PathType::Folder(vec!["db".to_owned(), "faction_banners_tables".to_owned()])) {
            get_data_from_all_sources!(self, get_faction_banner_data, data, processed_data, true);
        }
        if self.tool.get_ref_used_paths().contains(&PathType::Folder(vec!["db".to_owned(), "faction_uniform_colours_tables".to_owned()])) {
            get_data_from_all_sources!(self, get_faction_uniform_data, data, processed_data, true);
        }
        // Finally, grab the flag files. For that, get the paths from each faction's data, and request the flag icons.
        // These flag paths are already pre-processed to contain their full icon path, and a common slash format.
        let paths_to_use = processed_data.values()
            .map(|x| x.get("flags_path").unwrap()
                .split('/')
                .map(|x| x.to_owned())
                .collect::<Vec<String>>()
            )
            .filter_map(|x| if !x.is_empty() { Some(PathType::File(x.to_vec())) } else { None })
            .collect::<Vec<PathType>>();
        let receiver = CENTRAL_COMMAND.send_background(Command::GetPackedFilesFromAllSources(paths_to_use));
        let response = CentralCommand::recv(&receiver);
        let images_data = if let Response::HashMapDataSourceHashMapVecStringPackedFile(data) = response { data } else { panic!("{}{:?}", THREADS_COMMUNICATION_ERROR, response); };
        // Map the paths to be a single string, lowercase. That should speed-up things.
        let images_data: HashMap<DataSource, HashMap<String, PackedFile>> = images_data.iter().map(|(x, y)| (*x, y.par_iter().map(|(path, z)| (path.join("/").to_lowercase(), z.clone())).collect())).collect();
        // Once we got everything processed, build the items for the ListView.
        for (key, data) in processed_data.iter().sorted_by_key(|x| x.0) {
            let item = QStandardItem::from_q_string(&QString::from_std_str(&format!("{} - {}", data.get("screen_name").unwrap(), key))).into_ptr();
            item.set_data_2a(&QVariant::from_q_string(&QString::from_std_str(&serde_json::to_string(data).unwrap())), FACTION_DATA);
            // Image paths, we may or may not have them, so only try to load them if we actually have a path for them.
            if let Some(image_path) = data.get("flags_path") {
                let image_path_lowercase = image_path.to_lowercase();
                let mut image_data = None;
                if let Some(data) = images_data.get(&DataSource::PackFile) {
                    if let Some(image_packed_file) = data.get(&image_path_lowercase) {
                        image_data = Some(image_packed_file.get_raw_data().unwrap());
                    }
                }
                if image_data.is_none() {
                    if let Some(data) = images_data.get(&DataSource::ParentFiles) {
                        if let Some(image_packed_file) = data.get(&image_path_lowercase) {
                            image_data = Some(image_packed_file.get_raw_data().unwrap());
                        }
                    }
                }
                if image_data.is_none() {
                    if let Some(data) = images_data.get(&DataSource::GameFiles) {
                        if let Some(image_packed_file) = data.get(&image_path_lowercase) {
                            image_data = Some(image_packed_file.get_raw_data().unwrap());
                        }
                    }
                }
                // If we got an image, load it into an icon, and load its raw data into the item, for future use.
                if let Some(image_data) = image_data {
                    let byte_array = QByteArray::from_slice(&image_data);
                    let image = QPixmap::new();
                    image.load_from_data_q_byte_array(&byte_array);
                    item.set_icon(&QIcon::from_q_pixmap(&image));
                    // Store the icon for future use.
                    item.set_data_2a(&QVariant::from_q_byte_array(&byte_array), FACTION_ICON);
                }
            }
            // Finally, add the item to the list.
            self.faction_list_model.append_row_q_standard_item(item);
        }
        // Store the PackedFiles for use when saving.
        *self.tool.packed_files.borrow_mut() = data;
        Ok(())
    }
unsafe fn load_data ( & self ) -> Result < ( ) > { // Note: this data is HashMap<DataSource, HashMap<Path, PackedFile>>. let receiver = CENTRAL_COMMAND . send_background ( Command :: GetPackedFilesFromAllSources ( self . tool . used_paths . to_vec ( ) ) ) ; let response = CentralCommand :: recv ( & receiver ) ; let mut data = if let Response :: HashMapDataSourceHashMapVecStringPackedFile ( data ) = response { data } else { panic ! ( " " THREADS_COMMUNICATION_ERROR response ) ; } ; let mut processed_data = HashMap :: new ( ) ; // Get the table's data. get_data_from_all_sources ! ( self get_faction_data data processed_data true ) ; if self . tool . get_ref_used_paths ( ) . contains ( & PathType :: Folder ( vec ! [ " " to_owned ( ) " " to_owned ( ) ] ) ) { get_data_from_all_sources ! ( self get_faction_banner_data data processed_data true ) ; } if self . tool . get_ref_used_paths ( ) . contains ( & PathType :: Folder ( vec ! [ " " to_owned ( ) " " to_owned ( ) ] ) ) { get_data_from_all_sources ! ( self get_faction_uniform_data data processed_data true ) ; } // Finally, grab the flag files. For that, get the paths from each faction's data, and request the flag icons. // These flag paths are already pre-processed to contain their full icon path, and a common slash format. let paths_to_use = processed_data . values ( ) . map ( | x | x . get ( " " ) . unwrap ( ) . split ( '/' ) . map ( | x | x . to_owned ( ) ) . collect :: < Vec < String > > ( ) ) . filter_map ( | x | if ! x . is_empty ( ) { Some ( PathType :: File ( x . to_vec ( ) ) ) } else { None } ) . collect :: < Vec < PathType > > ( ) ; let receiver = CENTRAL_COMMAND . send_background ( Command :: GetPackedFilesFromAllSources ( paths_to_use ) ) ; let response = CentralCommand :: recv ( & receiver ) ; let images_data = if let Response :: HashMapDataSourceHashMapVecStringPackedFile ( data ) = response { data } else { panic ! ( " " THREADS_COMMUNICATION_ERROR response ) ; } ; // Map the paths to be a single string, lowercase. That should speed-up things. let images_data : HashMap < DataSource , HashMap < String , PackedFile > > = images_data . iter ( ) . map ( | ( x , y ) | ( * x , y . par_iter ( ) . map ( | ( path , z ) | ( path . join ( " " ) . to_lowercase ( ) , z . clone ( ) ) ) . collect ( ) ) ) . collect ( ) ; // Once we got everything processed, build the items for the ListView. for ( key , data ) in processed_data . iter ( ) . sorted_by_key ( | x | x . 0 ) { let item = QStandardItem :: from_q_string ( & QString :: from_std_str ( & format ! ( " " data get ( " " ) unwrap ( ) key ) ) ) . into_ptr ( ) ; item . set_data_2a ( & QVariant :: from_q_string ( & QString :: from_std_str ( & serde_json :: to_string ( data ) . unwrap ( ) ) ) , FACTION_DATA ) ; // Image paths, we may or may not have them, so only try to load them if we actually have a path for them. if let Some ( image_path ) = data . get ( " " ) { let image_path_lowercase = image_path . to_lowercase ( ) ; let mut image_data = None ; if let Some ( data ) = images_data . get ( & DataSource :: PackFile ) { if let Some ( image_packed_file ) = data . get ( & image_path_lowercase ) { image_data = Some ( image_packed_file . get_raw_data ( ) . unwrap ( ) ) ; } } if image_data . is_none ( ) { if let Some ( data ) = images_data . get ( & DataSource :: ParentFiles ) { if let Some ( image_packed_file ) = data . get ( & image_path_lowercase ) { image_data = Some ( image_packed_file . get_raw_data ( ) . unwrap ( ) ) ; } } } if image_data . is_none ( ) { if let Some ( data ) = images_data . get ( & DataSource :: GameFiles ) { if let Some ( image_packed_file ) = data . get ( & image_path_lowercase ) { image_data = Some ( image_packed_file . get_raw_data ( ) . unwrap ( ) ) ; } } } // If we got an image, load it into an icon, and load its raw data into the item, for future use. if let Some ( image_data ) = image_data { let byte_array = QByteArray :: from_slice ( & image_data ) ; let image = QPixmap :: new ( ) ; image . load_from_data_q_byte_array ( & byte_array ) ; item . set_icon ( & QIcon :: from_q_pixmap ( & image ) ) ; // Store the icon for future use. item . set_data_2a ( & QVariant :: from_q_byte_array ( & byte_array ) , FACTION_ICON ) ; } } // Finally, add the item to the list. self . faction_list_model . append_row_q_standard_item ( item ) ; } // Store the PackedFiles for use when saving. * self . tool . packed_files . borrow_mut ( ) = data ; Ok ( ( ) ) }
This function loads the data we need for the faction painter to the view, inside items in the ListView.
This function loads the data we need for the faction painter to the view inside items in the ListView .
&self
&self