pub unsafe fn load_clone_faction_dialog(&self) -> Result<()> {
        let source_selection = self.faction_list_view.selection_model().selection();
        let source_indexes = source_selection.indexes();

        if source_indexes.is_empty() {
            return Err(ErrorKind::GenericHTMLError("No faction selected".to_string()).into());
        }

        let source_model_index = self.faction_list_filter.map_to_source(source_indexes.at(0));
        let source_faction_name = self.faction_list_model.item_from_index(&source_model_index).text();
        self.new_faction_button_box.button(q_dialog_button_box::StandardButton::Ok).set_enabled(false);

        // Trick: get the model from another faction combo, and reuse it here.
        self.new_faction_name_combobox.set_model(&self.unit_variants_colours_faction_combobox.model());
        self.new_faction_name_combobox.set_current_text(&source_faction_name);

        let dialog: QPtr<QDialog> = self.new_faction_widget.static_downcast();
        if dialog.exec() == 1 {

            // Save the source faction. Do it through selection to avoid double saving breaking things.
            self.faction_list_view.selection_model().select_q_item_selection_q_flags_selection_flag(&self.faction_list_view.selection_model().selection(), SelectionFlag::Toggle.into());

            // Clone the source faction, updating its relevant keys in the process.
            let new_faction_name = self.new_faction_name_combobox.current_text();
            let new_item = (*self.faction_list_model.item_from_index(&source_model_index)).clone();
            new_item.set_text(&new_faction_name);

            // Perform the needed edits to the data, so it uses the new faction key.
            //let mut data: HashMap<String, String> = serde_json::from_str(&new_item.data_1a(UNIT_DATA).to_string().to_std_string()).unwrap();
            //new_item.set_data_2a(&QVariant::from_q_string(&QString::from_std_str(&serde_json::to_string(&data).unwrap())), UNIT_DATA);

            // Append the new item.
            self.faction_list_model.append_row_q_standard_item(new_item);
            let new_index = self.faction_list_model.index_from_item(new_item);

            // Clear the filters (just in case) and open the new faction.
            self.get_ref_faction_list_filter_line_edit().clear();
            self.get_ref_faction_list_filter().sort_2a(0, SortOrder::AscendingOrder);
            self.get_ref_faction_list_view().set_current_index(&self.get_ref_faction_list_filter().map_from_source(&new_index));
        }

        Ok(())
    }
/// Function to load the `Clone Faction` dialog.
Function to load the `Clone Faction` dialog.
Function to load the ` Clone Faction ` dialog .
pub unsafe fn load_clone_faction_dialog(&self) -> Result<()> {
        let source_selection = self.faction_list_view.selection_model().selection();
        let source_indexes = source_selection.indexes();
        if source_indexes.is_empty() {
            return Err(ErrorKind::GenericHTMLError("No faction selected".to_string()).into());
        }
        let source_model_index = self.faction_list_filter.map_to_source(source_indexes.at(0));
        let source_faction_name = self.faction_list_model.item_from_index(&source_model_index).text();
        self.new_faction_button_box.button(q_dialog_button_box::StandardButton::Ok).set_enabled(false);
        // Trick: get the model from another faction combo, and reuse it here.
        self.new_faction_name_combobox.set_model(&self.unit_variants_colours_faction_combobox.model());
        self.new_faction_name_combobox.set_current_text(&source_faction_name);
        let dialog: QPtr<QDialog> = self.new_faction_widget.static_downcast();
        if dialog.exec() == 1 {
            // Save the source faction. Do it through selection to avoid double saving breaking things.
            self.faction_list_view.selection_model().select_q_item_selection_q_flags_selection_flag(&self.faction_list_view.selection_model().selection(), SelectionFlag::Toggle.into());
            // Clone the source faction, updating its relevant keys in the process.
            let new_faction_name = self.new_faction_name_combobox.current_text();
            let new_item = (*self.faction_list_model.item_from_index(&source_model_index)).clone();
            new_item.set_text(&new_faction_name);
            // Perform the needed edits to the data, so it uses the new faction key.
            //let mut data: HashMap<String, String> = serde_json::from_str(&new_item.data_1a(UNIT_DATA).to_string().to_std_string()).unwrap();
            //new_item.set_data_2a(&QVariant::from_q_string(&QString::from_std_str(&serde_json::to_string(&data).unwrap())), UNIT_DATA);
            // Append the new item.
            self.faction_list_model.append_row_q_standard_item(new_item);
            let new_index = self.faction_list_model.index_from_item(new_item);
            // Clear the filters (just in case) and open the new faction.
            self.get_ref_faction_list_filter_line_edit().clear();
            self.get_ref_faction_list_filter().sort_2a(0, SortOrder::AscendingOrder);
            self.get_ref_faction_list_view().set_current_index(&self.get_ref_faction_list_filter().map_from_source(&new_index));
        }
        Ok(())
    }
pub unsafe fn load_clone_faction_dialog ( & self ) -> Result < ( ) > { let source_selection = self . faction_list_view . selection_model ( ) . selection ( ) ; let source_indexes = source_selection . indexes ( ) ; if source_indexes . is_empty ( ) { return Err ( ErrorKind :: GenericHTMLError ( " " . to_string ( ) ) . into ( ) ) ; } let source_model_index = self . faction_list_filter . map_to_source ( source_indexes . at ( 0 ) ) ; let source_faction_name = self . faction_list_model . item_from_index ( & source_model_index ) . text ( ) ; self . new_faction_button_box . button ( q_dialog_button_box :: StandardButton :: Ok ) . set_enabled ( false ) ; // Trick: get the model from another faction combo, and reuse it here. self . new_faction_name_combobox . set_model ( & self . unit_variants_colours_faction_combobox . model ( ) ) ; self . new_faction_name_combobox . set_current_text ( & source_faction_name ) ; let dialog : QPtr < QDialog > = self . new_faction_widget . static_downcast ( ) ; if dialog . exec ( ) == 1 { // Save the source faction. Do it through selection to avoid double saving breaking things. self . faction_list_view . selection_model ( ) . select_q_item_selection_q_flags_selection_flag ( & self . faction_list_view . selection_model ( ) . selection ( ) , SelectionFlag :: Toggle . into ( ) ) ; // Clone the source faction, updating its relevant keys in the process. let new_faction_name = self . new_faction_name_combobox . current_text ( ) ; let new_item = ( * self . faction_list_model . item_from_index ( & source_model_index ) ) . clone ( ) ; new_item . set_text ( & new_faction_name ) ; // Perform the needed edits to the data, so it uses the new faction key. //let mut data: HashMap<String, String> = serde_json::from_str(&new_item.data_1a(UNIT_DATA).to_string().to_std_string()).unwrap(); //new_item.set_data_2a(&QVariant::from_q_string(&QString::from_std_str(&serde_json::to_string(&data).unwrap())), UNIT_DATA); // Append the new item. self . faction_list_model . append_row_q_standard_item ( new_item ) ; let new_index = self . faction_list_model . index_from_item ( new_item ) ; // Clear the filters (just in case) and open the new faction. self . get_ref_faction_list_filter_line_edit ( ) . clear ( ) ; self . get_ref_faction_list_filter ( ) . sort_2a ( 0 , SortOrder :: AscendingOrder ) ; self . get_ref_faction_list_view ( ) . set_current_index ( & self . get_ref_faction_list_filter ( ) . map_from_source ( & new_index ) ) ; } Ok ( ( ) ) }
Function to load the `Clone Faction` dialog.
Function to load the ` Clone Faction ` dialog .
&self
&self