unsafe fn paste_as_it_fits(&self, text: &[Vec<&str>], indexes: &[Ref<QModelIndex>], app_ui: &Rc<AppUI>, pack_file_contents_ui: &Rc<PackFileContentsUI>) {

        // We're going to try and check in square mode. That means, start in the selected cell, then right
        // until we reach a \n, then return to the initial column. Due to how sorting works, we have to do
        // a test pass first and get all the real AND VALID indexes, then try to paste on them.
        let horizontal_header = self.table_view_primary.horizontal_header();
        let vertical_header = self.table_view_primary.vertical_header();

        // Get the base index of the square. If no index is being provided, we assume we have to paste all in new rows.
        let (base_index_visual, mut visual_row) = if !indexes.is_empty() {
            (Some(&indexes[0]), vertical_header.visual_index(indexes[0].row()))
        } else {
            (None, self.table_model.row_count_0a())
        };

        let definition = self.get_ref_table_definition();
        let fields_processed = definition.get_fields_processed();

        let mut real_cells = vec![];
        let mut added_rows = 0;
        for row in text {
            let mut visual_column = match base_index_visual {
                Some(base_index_visual) => horizontal_header.visual_index(base_index_visual.column()),
                None => 0,
            };

            let mut real_row = self.table_filter.map_to_source(&self.table_filter.index_2a(visual_row, visual_column)).row();

            for text in row {

                // Depending on the column, we try to encode the data in one format or another, or we just skip it.
                let real_column = horizontal_header.logical_index(visual_column);

                if let Some(field) = fields_processed.get(real_column as usize) {

                    // Check if, according to the definition, we have a valid value for the type.
                    let is_valid_data = match field.get_ref_field_type() {
                        FieldType::Boolean => !(text.to_lowercase() != "true" && text.to_lowercase() != "false" && text != &"1" && text != &"0"),
                        FieldType::F32 => text.parse::<f32>().is_ok(),
                        FieldType::F64 => text.parse::<f64>().is_ok(),
                        FieldType::I16 => text.parse::<i16>().is_ok() || text.parse::<f32>().is_ok(),
                        FieldType::I32 => text.parse::<i32>().is_ok() || text.parse::<f32>().is_ok(),
                        FieldType::I64 => text.parse::<i64>().is_ok() || text.parse::<f32>().is_ok(),
                        FieldType::ColourRGB => u32::from_str_radix(text, 16).is_ok(),

                        // All these are Strings, so we can skip their checks....
                        FieldType::StringU8 |
                        FieldType::StringU16 |
                        FieldType::OptionalStringU8 |
                        FieldType::OptionalStringU16 => true,

                        // Ignore sequences.
                        FieldType::SequenceU16(_) | FieldType::SequenceU32(_) => false,
                    };

                    // If it's valid, add it to the real_cells list.
                    if is_valid_data {

                        // If real_row is -1 (invalid), then we need to add an empty row to the model (NOT TO THE FILTER)
                        // because that means we have no row for that position, and we need one.
                        if real_row == -1 {
                            let row = get_new_row(&self.get_ref_table_definition(), self.get_ref_table_name().as_deref());
                            for index in 0..row.count_0a() {
                                row.value_1a(index).set_data_2a(&QVariant::from_bool(true), ITEM_IS_ADDED);
                            }
                            self.table_model.append_row_q_list_of_q_standard_item(&row);
                            real_row = self.table_model.row_count_0a() - 1;
                            added_rows += 1;
                        }
                        real_cells.push((self.table_model.index_2a(real_row, real_column), *text));
                    }
                }
                visual_column += 1;
            }
            visual_row += 1;
        }

        // We need to update the undo model here, because otherwise it'll start triggering crashes
        // in case the first thing to paste is equal to the current value. In that case, the set_data
        // will not trigger, and the update_undo_model will not trigger either, causing a crash if
        // immediately after that we try to paste something in a new line (which will not exist in the undo model).
        {
            update_undo_model(&self.get_mut_ptr_table_model(), &self.get_mut_ptr_undo_model());
        }

        self.set_data_on_cells(&real_cells, added_rows, &[], app_ui, pack_file_contents_ui);
    }
/// This function pastes the provided text into the table as it fits, following a square strategy starting in the first selected index.
This function pastes the provided text into the table as it fits, following a square strategy starting in the first selected index.
This function pastes the provided text into the table as it fits following a square strategy starting in the first selected index .
unsafe fn paste_as_it_fits(&self, text: &[Vec<&str>], indexes: &[Ref<QModelIndex>], app_ui: &Rc<AppUI>, pack_file_contents_ui: &Rc<PackFileContentsUI>) {
        // We're going to try and check in square mode. That means, start in the selected cell, then right
        // until we reach a \n, then return to the initial column. Due to how sorting works, we have to do
        // a test pass first and get all the real AND VALID indexes, then try to paste on them.
        let horizontal_header = self.table_view_primary.horizontal_header();
        let vertical_header = self.table_view_primary.vertical_header();
        // Get the base index of the square. If no index is being provided, we assume we have to paste all in new rows.
        let (base_index_visual, mut visual_row) = if !indexes.is_empty() {
            (Some(&indexes[0]), vertical_header.visual_index(indexes[0].row()))
        } else {
            (None, self.table_model.row_count_0a())
        };
        let definition = self.get_ref_table_definition();
        let fields_processed = definition.get_fields_processed();
        let mut real_cells = vec![];
        let mut added_rows = 0;
        for row in text {
            let mut visual_column = match base_index_visual {
                Some(base_index_visual) => horizontal_header.visual_index(base_index_visual.column()),
                None => 0,
            };
            let mut real_row = self.table_filter.map_to_source(&self.table_filter.index_2a(visual_row, visual_column)).row();
            for text in row {
                // Depending on the column, we try to encode the data in one format or another, or we just skip it.
                let real_column = horizontal_header.logical_index(visual_column);
                if let Some(field) = fields_processed.get(real_column as usize) {
                    // Check if, according to the definition, we have a valid value for the type.
                    let is_valid_data = match field.get_ref_field_type() {
                        FieldType::Boolean => !(text.to_lowercase() != "true" && text.to_lowercase() != "false" && text != &"1" && text != &"0"),
                        FieldType::F32 => text.parse::<f32>().is_ok(),
                        FieldType::F64 => text.parse::<f64>().is_ok(),
                        FieldType::I16 => text.parse::<i16>().is_ok() || text.parse::<f32>().is_ok(),
                        FieldType::I32 => text.parse::<i32>().is_ok() || text.parse::<f32>().is_ok(),
                        FieldType::I64 => text.parse::<i64>().is_ok() || text.parse::<f32>().is_ok(),
                        FieldType::ColourRGB => u32::from_str_radix(text, 16).is_ok(),
                        // All these are Strings, so we can skip their checks....
                        FieldType::StringU8 |
                        FieldType::StringU16 |
                        FieldType::OptionalStringU8 |
                        FieldType::OptionalStringU16 => true,
                        // Ignore sequences.
                        FieldType::SequenceU16(_) | FieldType::SequenceU32(_) => false,
                    };
                    // If it's valid, add it to the real_cells list.
                    if is_valid_data {
                        // If real_row is -1 (invalid), then we need to add an empty row to the model (NOT TO THE FILTER)
                        // because that means we have no row for that position, and we need one.
                        if real_row == -1 {
                            let row = get_new_row(&self.get_ref_table_definition(), self.get_ref_table_name().as_deref());
                            for index in 0..row.count_0a() {
                                row.value_1a(index).set_data_2a(&QVariant::from_bool(true), ITEM_IS_ADDED);
                            }
                            self.table_model.append_row_q_list_of_q_standard_item(&row);
                            real_row = self.table_model.row_count_0a() - 1;
                            added_rows += 1;
                        }
                        real_cells.push((self.table_model.index_2a(real_row, real_column), *text));
                    }
                }
                visual_column += 1;
            }
            visual_row += 1;
        }
        // We need to update the undo model here, because otherwise it'll start triggering crashes
        // in case the first thing to paste is equal to the current value. In that case, the set_data
        // will not trigger, and the update_undo_model will not trigger either, causing a crash if
        // immediately after that we try to paste something in a new line (which will not exist in the undo model).
        {
            update_undo_model(&self.get_mut_ptr_table_model(), &self.get_mut_ptr_undo_model());
        }
        self.set_data_on_cells(&real_cells, added_rows, &[], app_ui, pack_file_contents_ui);
    }
unsafe fn paste_as_it_fits ( & self , text : & [ Vec < & str > ] , indexes : & [ Ref < QModelIndex > ] , app_ui : & Rc < AppUI > , pack_file_contents_ui : & Rc < PackFileContentsUI > ) { // We're going to try and check in square mode. That means, start in the selected cell, then right // until we reach a \n, then return to the initial column. Due to how sorting works, we have to do // a test pass first and get all the real AND VALID indexes, then try to paste on them. let horizontal_header = self . table_view_primary . horizontal_header ( ) ; let vertical_header = self . table_view_primary . vertical_header ( ) ; // Get the base index of the square. If no index is being provided, we assume we have to paste all in new rows. let ( base_index_visual , mut visual_row ) = if ! indexes . is_empty ( ) { ( Some ( & indexes [ 0 ] ) , vertical_header . visual_index ( indexes [ 0 ] . row ( ) ) ) } else { ( None , self . table_model . row_count_0a ( ) ) } ; let definition = self . get_ref_table_definition ( ) ; let fields_processed = definition . get_fields_processed ( ) ; let mut real_cells = vec ! [ ] ; let mut added_rows = 0 ; for row in text { let mut visual_column = match base_index_visual { Some ( base_index_visual ) => horizontal_header . visual_index ( base_index_visual . column ( ) ) , None => 0 , } ; let mut real_row = self . table_filter . map_to_source ( & self . table_filter . index_2a ( visual_row , visual_column ) ) . row ( ) ; for text in row { // Depending on the column, we try to encode the data in one format or another, or we just skip it. let real_column = horizontal_header . logical_index ( visual_column ) ; if let Some ( field ) = fields_processed . get ( real_column as usize ) { // Check if, according to the definition, we have a valid value for the type. let is_valid_data = match field . get_ref_field_type ( ) { FieldType :: Boolean => ! ( text . to_lowercase ( ) != " " && text . to_lowercase ( ) != " " && text != & " " && text != & " " ) , FieldType :: F32 => text . parse :: < f32 > ( ) . is_ok ( ) , FieldType :: F64 => text . parse :: < f64 > ( ) . is_ok ( ) , FieldType :: I16 => text . parse :: < i16 > ( ) . is_ok ( ) || text . parse :: < f32 > ( ) . is_ok ( ) , FieldType :: I32 => text . parse :: < i32 > ( ) . is_ok ( ) || text . parse :: < f32 > ( ) . is_ok ( ) , FieldType :: I64 => text . parse :: < i64 > ( ) . is_ok ( ) || text . parse :: < f32 > ( ) . is_ok ( ) , FieldType :: ColourRGB => u32 :: from_str_radix ( text , 16 ) . is_ok ( ) , // All these are Strings, so we can skip their checks.... FieldType :: StringU8 | FieldType :: StringU16 | FieldType :: OptionalStringU8 | FieldType :: OptionalStringU16 => true , // Ignore sequences. FieldType :: SequenceU16 ( _ ) | FieldType :: SequenceU32 ( _ ) => false , } ; // If it's valid, add it to the real_cells list. if is_valid_data { // If real_row is -1 (invalid), then we need to add an empty row to the model (NOT TO THE FILTER) // because that means we have no row for that position, and we need one. if real_row == - 1 { let row = get_new_row ( & self . get_ref_table_definition ( ) , self . get_ref_table_name ( ) . as_deref ( ) ) ; for index in 0 .. row . count_0a ( ) { row . value_1a ( index ) . set_data_2a ( & QVariant :: from_bool ( true ) , ITEM_IS_ADDED ) ; } self . table_model . append_row_q_list_of_q_standard_item ( & row ) ; real_row = self . table_model . row_count_0a ( ) - 1 ; added_rows += 1 ; } real_cells . push ( ( self . table_model . index_2a ( real_row , real_column ) , * text ) ) ; } } visual_column += 1 ; } visual_row += 1 ; } // We need to update the undo model here, because otherwise it'll start triggering crashes // in case the first thing to paste is equal to the current value. In that case, the set_data // will not trigger, and the update_undo_model will not trigger either, causing a crash if // immediately after that we try to paste something in a new line (which will not exist in the undo model). { update_undo_model ( & self . get_mut_ptr_table_model ( ) , & self . get_mut_ptr_undo_model ( ) ) ; } self . set_data_on_cells ( & real_cells , added_rows , & [ ] , app_ui , pack_file_contents_ui ) ; }
This function pastes the provided text into the table as it fits, following a square strategy starting in the first selected index.
This function pastes the provided text into the table as it fits following a square strategy starting in the first selected index .
&self
text
&[Vec<&str>]
indexes
&[Ref<QModelIndex>]
app_ui
&Rc<AppUI>
pack_file_contents_ui
&Rc<PackFileContentsUI>
&self
text
&[Vec<&str>]
indexes
&[Ref<QModelIndex>]
app_ui
&Rc<AppUI>
pack_file_contents_ui
&Rc<PackFileContentsUI>