pub unsafe fn load_copy_unit_dialog(&self) -> Result<()> {
        let source_unit = self.unit_list_view.selection_model().selection();
        if source_unit.count_0a() != 1 {
            return Err(ErrorKind::GenericHTMLError("No unit selected".to_string()).into());
        }

        let source_unit_real = self.get_ref_unit_list_filter().map_to_source(&source_unit.take_at(0).indexes().take_at(0));
        let source_unit_name = self.get_ref_unit_list_model().item_from_index(&source_unit_real).text();
        self.copy_unit_button_box.button(q_dialog_button_box::StandardButton::Ok).set_enabled(false);

        // Copy the model of the unit list and sort it, because here we don't use an intermediate filter.
        self.copy_unit_new_unit_name_combobox_model.clear();

        for row in 0..self.unit_list_model.row_count_0a() {
            let item = QStandardItem::from_q_string(&self.unit_list_model.item_1a(row).text());
            self.copy_unit_new_unit_name_combobox_model.append_row_q_standard_item(item.into_ptr());
        }

        self.copy_unit_new_unit_name_combobox_model.sort_2a(0, SortOrder::AscendingOrder);
        self.copy_unit_new_unit_name_combobox.set_current_text(&source_unit_name);

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

            // Save the source unit.
            self.save_from_detailed_view(source_unit_real.as_ref());

            // Clone the source unit, updating its relevant keys in the process.
            let new_item = (*self.unit_list_model.item_from_index(&source_unit_real)).clone();
            let new_unit_name = self.copy_unit_new_unit_name_combobox.current_text();
            new_item.set_text(&new_unit_name);

            let mut data: HashMap<String, String> = serde_json::from_str(&new_item.data_1a(UNIT_DATA).to_string().to_std_string()).unwrap();
            data.insert("main_units_unit".to_owned(), new_unit_name.to_std_string());
            data.insert("land_units_key".to_owned(), new_unit_name.to_std_string());
            self.update_keys(&mut data);
            new_item.set_data_2a(&QVariant::from_q_string(&QString::from_std_str(&serde_json::to_string(&data).unwrap())), UNIT_DATA);

            self.unit_list_model.append_row_q_standard_item(new_item);
            let new_index = self.unit_list_model.index_from_item(new_item);

            // Clear the filters (just in case) and open the new unit.
            self.get_ref_unit_list_filter_line_edit().clear();
            self.get_ref_unit_list_filter().sort_2a(0, SortOrder::AscendingOrder);
            self.get_ref_unit_list_view().set_current_index(&self.get_ref_unit_list_filter().map_from_source(&new_index));
        }

        Ok(())
    }
/// Function to load the `Copy Unit` dialog.
Function to load the `Copy Unit` dialog.
Function to load the ` Copy Unit ` dialog .
pub unsafe fn load_copy_unit_dialog(&self) -> Result<()> {
        let source_unit = self.unit_list_view.selection_model().selection();
        if source_unit.count_0a() != 1 {
            return Err(ErrorKind::GenericHTMLError("No unit selected".to_string()).into());
        }
        let source_unit_real = self.get_ref_unit_list_filter().map_to_source(&source_unit.take_at(0).indexes().take_at(0));
        let source_unit_name = self.get_ref_unit_list_model().item_from_index(&source_unit_real).text();
        self.copy_unit_button_box.button(q_dialog_button_box::StandardButton::Ok).set_enabled(false);
        // Copy the model of the unit list and sort it, because here we don't use an intermediate filter.
        self.copy_unit_new_unit_name_combobox_model.clear();
        for row in 0..self.unit_list_model.row_count_0a() {
            let item = QStandardItem::from_q_string(&self.unit_list_model.item_1a(row).text());
            self.copy_unit_new_unit_name_combobox_model.append_row_q_standard_item(item.into_ptr());
        }
        self.copy_unit_new_unit_name_combobox_model.sort_2a(0, SortOrder::AscendingOrder);
        self.copy_unit_new_unit_name_combobox.set_current_text(&source_unit_name);
        let dialog: QPtr<QDialog> = self.copy_unit_widget.static_downcast();
        if dialog.exec() == 1 {
            // Save the source unit.
            self.save_from_detailed_view(source_unit_real.as_ref());
            // Clone the source unit, updating its relevant keys in the process.
            let new_item = (*self.unit_list_model.item_from_index(&source_unit_real)).clone();
            let new_unit_name = self.copy_unit_new_unit_name_combobox.current_text();
            new_item.set_text(&new_unit_name);
            let mut data: HashMap<String, String> = serde_json::from_str(&new_item.data_1a(UNIT_DATA).to_string().to_std_string()).unwrap();
            data.insert("main_units_unit".to_owned(), new_unit_name.to_std_string());
            data.insert("land_units_key".to_owned(), new_unit_name.to_std_string());
            self.update_keys(&mut data);
            new_item.set_data_2a(&QVariant::from_q_string(&QString::from_std_str(&serde_json::to_string(&data).unwrap())), UNIT_DATA);
            self.unit_list_model.append_row_q_standard_item(new_item);
            let new_index = self.unit_list_model.index_from_item(new_item);
            // Clear the filters (just in case) and open the new unit.
            self.get_ref_unit_list_filter_line_edit().clear();
            self.get_ref_unit_list_filter().sort_2a(0, SortOrder::AscendingOrder);
            self.get_ref_unit_list_view().set_current_index(&self.get_ref_unit_list_filter().map_from_source(&new_index));
        }
        Ok(())
    }
pub unsafe fn load_copy_unit_dialog ( & self ) -> Result < ( ) > { let source_unit = self . unit_list_view . selection_model ( ) . selection ( ) ; if source_unit . count_0a ( ) != 1 { return Err ( ErrorKind :: GenericHTMLError ( " " . to_string ( ) ) . into ( ) ) ; } let source_unit_real = self . get_ref_unit_list_filter ( ) . map_to_source ( & source_unit . take_at ( 0 ) . indexes ( ) . take_at ( 0 ) ) ; let source_unit_name = self . get_ref_unit_list_model ( ) . item_from_index ( & source_unit_real ) . text ( ) ; self . copy_unit_button_box . button ( q_dialog_button_box :: StandardButton :: Ok ) . set_enabled ( false ) ; // Copy the model of the unit list and sort it, because here we don't use an intermediate filter. self . copy_unit_new_unit_name_combobox_model . clear ( ) ; for row in 0 .. self . unit_list_model . row_count_0a ( ) { let item = QStandardItem :: from_q_string ( & self . unit_list_model . item_1a ( row ) . text ( ) ) ; self . copy_unit_new_unit_name_combobox_model . append_row_q_standard_item ( item . into_ptr ( ) ) ; } self . copy_unit_new_unit_name_combobox_model . sort_2a ( 0 , SortOrder :: AscendingOrder ) ; self . copy_unit_new_unit_name_combobox . set_current_text ( & source_unit_name ) ; let dialog : QPtr < QDialog > = self . copy_unit_widget . static_downcast ( ) ; if dialog . exec ( ) == 1 { // Save the source unit. self . save_from_detailed_view ( source_unit_real . as_ref ( ) ) ; // Clone the source unit, updating its relevant keys in the process. let new_item = ( * self . unit_list_model . item_from_index ( & source_unit_real ) ) . clone ( ) ; let new_unit_name = self . copy_unit_new_unit_name_combobox . current_text ( ) ; new_item . set_text ( & new_unit_name ) ; let mut data : HashMap < String , String > = serde_json :: from_str ( & new_item . data_1a ( UNIT_DATA ) . to_string ( ) . to_std_string ( ) ) . unwrap ( ) ; data . insert ( " " . to_owned ( ) , new_unit_name . to_std_string ( ) ) ; data . insert ( " " . to_owned ( ) , new_unit_name . to_std_string ( ) ) ; self . update_keys ( & mut data ) ; new_item . set_data_2a ( & QVariant :: from_q_string ( & QString :: from_std_str ( & serde_json :: to_string ( & data ) . unwrap ( ) ) ) , UNIT_DATA ) ; self . unit_list_model . append_row_q_standard_item ( new_item ) ; let new_index = self . unit_list_model . index_from_item ( new_item ) ; // Clear the filters (just in case) and open the new unit. self . get_ref_unit_list_filter_line_edit ( ) . clear ( ) ; self . get_ref_unit_list_filter ( ) . sort_2a ( 0 , SortOrder :: AscendingOrder ) ; self . get_ref_unit_list_view ( ) . set_current_index ( & self . get_ref_unit_list_filter ( ) . map_from_source ( & new_index ) ) ; } Ok ( ( ) ) }
Function to load the `Copy Unit` dialog.
Function to load the ` Copy Unit ` dialog .
&self
&self