pub unsafe fn insert_rows(&self, clone: bool) {

        // Get the indexes ready for battle.
        let selection = self.table_view_primary.selection_model().selection();
        let indexes = self.table_filter.map_selection_to_source(&selection).indexes();
        let mut indexes_sorted = (0..indexes.count_0a()).map(|x| indexes.at(x)).collect::<Vec<Ref<QModelIndex>>>();
        sort_indexes_by_model(&mut indexes_sorted);
        dedup_indexes_per_row(&mut indexes_sorted);
        let mut row_numbers = vec![];

        // If nothing is selected, we just append one new row at the end. This only happens when adding empty rows, so...
        if indexes_sorted.is_empty() {
            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);
            row_numbers.push(self.table_model.row_count_0a() - 1);
        }

        let selection_model = self.table_view_primary.selection_model();
        selection_model.clear();

        for index in indexes_sorted.iter().rev() {
            row_numbers.push(index.row() + (indexes_sorted.len() - row_numbers.len() - 1) as i32);

            // If we want to clone, we copy the currently selected row. If not, we just create a new one.
            let row = if clone {
                let columns = self.table_model.column_count_0a();
                let qlist = QListOfQStandardItem::new();
                for column in 0..columns {
                    let original_item = self.table_model.item_2a(index.row(), column);
                    let item = (*original_item).clone();
                    item.set_data_2a(&QVariant::from_bool(true), ITEM_IS_ADDED);
                    item.set_data_2a(&QVariant::from_bool(false), ITEM_IS_MODIFIED);
                    qlist.append_q_standard_item(&item.as_mut_raw_ptr());
                }
                qlist
            } else {
                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);
                }
                row
            };
            self.table_model.insert_row_int_q_list_of_q_standard_item(index.row(), &row);

            // Select the row.
            let model_index_filtered = self.table_filter.map_from_source(&self.table_model.index_2a(index.row(), 0));
            if model_index_filtered.is_valid() {
                selection_model.select_q_model_index_q_flags_selection_flag(
                    &model_index_filtered,
                    SelectionFlag::Select | SelectionFlag::Rows
                );
            }
        }

        // The undo mode needs this reversed.
        self.history_undo.write().unwrap().push(TableOperations::AddRows(row_numbers));
        self.history_redo.write().unwrap().clear();
        self.start_delayed_updates_timer();
        self.update_line_counter();
        update_undo_model(&self.get_mut_ptr_table_model(), &self.get_mut_ptr_undo_model());
    }
/// This function is used to insert new rows into a table.
///
/// If clone = true, the appended rows are copies of the selected ones.
This function is used to insert new rows into a table.
If clone = true, the appended rows are copies of the selected ones.
This function is used to insert new rows into a table . If clone = true the appended rows are copies of the selected ones .
pub unsafe fn insert_rows(&self, clone: bool) {
        // Get the indexes ready for battle.
        let selection = self.table_view_primary.selection_model().selection();
        let indexes = self.table_filter.map_selection_to_source(&selection).indexes();
        let mut indexes_sorted = (0..indexes.count_0a()).map(|x| indexes.at(x)).collect::<Vec<Ref<QModelIndex>>>();
        sort_indexes_by_model(&mut indexes_sorted);
        dedup_indexes_per_row(&mut indexes_sorted);
        let mut row_numbers = vec![];
        // If nothing is selected, we just append one new row at the end. This only happens when adding empty rows, so...
        if indexes_sorted.is_empty() {
            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);
            row_numbers.push(self.table_model.row_count_0a() - 1);
        }
        let selection_model = self.table_view_primary.selection_model();
        selection_model.clear();
        for index in indexes_sorted.iter().rev() {
            row_numbers.push(index.row() + (indexes_sorted.len() - row_numbers.len() - 1) as i32);
            // If we want to clone, we copy the currently selected row. If not, we just create a new one.
            let row = if clone {
                let columns = self.table_model.column_count_0a();
                let qlist = QListOfQStandardItem::new();
                for column in 0..columns {
                    let original_item = self.table_model.item_2a(index.row(), column);
                    let item = (*original_item).clone();
                    item.set_data_2a(&QVariant::from_bool(true), ITEM_IS_ADDED);
                    item.set_data_2a(&QVariant::from_bool(false), ITEM_IS_MODIFIED);
                    qlist.append_q_standard_item(&item.as_mut_raw_ptr());
                }
                qlist
            } else {
                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);
                }
                row
            };
            self.table_model.insert_row_int_q_list_of_q_standard_item(index.row(), &row);
            // Select the row.
            let model_index_filtered = self.table_filter.map_from_source(&self.table_model.index_2a(index.row(), 0));
            if model_index_filtered.is_valid() {
                selection_model.select_q_model_index_q_flags_selection_flag(
                    &model_index_filtered,
                    SelectionFlag::Select | SelectionFlag::Rows
                );
            }
        }
        // The undo mode needs this reversed.
        self.history_undo.write().unwrap().push(TableOperations::AddRows(row_numbers));
        self.history_redo.write().unwrap().clear();
        self.start_delayed_updates_timer();
        self.update_line_counter();
        update_undo_model(&self.get_mut_ptr_table_model(), &self.get_mut_ptr_undo_model());
    }
pub unsafe fn insert_rows ( & self , clone : bool ) { // Get the indexes ready for battle. let selection = self . table_view_primary . selection_model ( ) . selection ( ) ; let indexes = self . table_filter . map_selection_to_source ( & selection ) . indexes ( ) ; let mut indexes_sorted = ( 0 .. indexes . count_0a ( ) ) . map ( | x | indexes . at ( x ) ) . collect :: < Vec < Ref < QModelIndex > > > ( ) ; sort_indexes_by_model ( & mut indexes_sorted ) ; dedup_indexes_per_row ( & mut indexes_sorted ) ; let mut row_numbers = vec ! [ ] ; // If nothing is selected, we just append one new row at the end. This only happens when adding empty rows, so... if indexes_sorted . is_empty ( ) { 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 ) ; row_numbers . push ( self . table_model . row_count_0a ( ) - 1 ) ; } let selection_model = self . table_view_primary . selection_model ( ) ; selection_model . clear ( ) ; for index in indexes_sorted . iter ( ) . rev ( ) { row_numbers . push ( index . row ( ) + ( indexes_sorted . len ( ) - row_numbers . len ( ) - 1 ) as i32 ) ; // If we want to clone, we copy the currently selected row. If not, we just create a new one. let row = if clone { let columns = self . table_model . column_count_0a ( ) ; let qlist = QListOfQStandardItem :: new ( ) ; for column in 0 .. columns { let original_item = self . table_model . item_2a ( index . row ( ) , column ) ; let item = ( * original_item ) . clone ( ) ; item . set_data_2a ( & QVariant :: from_bool ( true ) , ITEM_IS_ADDED ) ; item . set_data_2a ( & QVariant :: from_bool ( false ) , ITEM_IS_MODIFIED ) ; qlist . append_q_standard_item ( & item . as_mut_raw_ptr ( ) ) ; } qlist } else { 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 ) ; } row } ; self . table_model . insert_row_int_q_list_of_q_standard_item ( index . row ( ) , & row ) ; // Select the row. let model_index_filtered = self . table_filter . map_from_source ( & self . table_model . index_2a ( index . row ( ) , 0 ) ) ; if model_index_filtered . is_valid ( ) { selection_model . select_q_model_index_q_flags_selection_flag ( & model_index_filtered , SelectionFlag :: Select | SelectionFlag :: Rows ) ; } } // The undo mode needs this reversed. self . history_undo . write ( ) . unwrap ( ) . push ( TableOperations :: AddRows ( row_numbers ) ) ; self . history_redo . write ( ) . unwrap ( ) . clear ( ) ; self . start_delayed_updates_timer ( ) ; self . update_line_counter ( ) ; update_undo_model ( & self . get_mut_ptr_table_model ( ) , & self . get_mut_ptr_undo_model ( ) ) ; }
This function is used to insert new rows into a table.
This function is used to insert new rows into a table .
&self
clone
bool
&self
clone
bool