lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master adc4089 28/46: Optimize changing grid dimensi


From: Greg Chicares
Subject: [lmi-commits] [lmi] master adc4089 28/46: Optimize changing grid dimensions when pasting into the census
Date: Wed, 22 Jul 2020 11:05:14 -0400 (EDT)

branch: master
commit adc408946ba67218e9fb7a5e36220751c0bcd7ac
Author: Vadim Zeitlin <vadim@tt-solutions.com>
Commit: Vadim Zeitlin <vadim@tt-solutions.com>

    Optimize changing grid dimensions when pasting into the census
    
    There is no need to delete all the rows and then add them back, it's
    enough to just delete or append the extraneous or missing ones.
    
    We also don't need to do anything at all with the columns, as they're
    taken care of by update_visible_columns(), called from Update() just
    below, already.
---
 census_view.cpp | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/census_view.cpp b/census_view.cpp
index 42dda09..edc6e40 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -3161,6 +3161,8 @@ void CensusGridView::UponPasteCensus(wxCommandEvent&)
         return;
         }
 
+    auto const old_rows = grid_table_->GetNumberRows();
+
     if(!document().IsModified() && !document().GetDocumentSaved())
         {
         case_parms ().clear();
@@ -3186,27 +3188,22 @@ void CensusGridView::UponPasteCensus(wxCommandEvent&)
         std::copy(cells.begin(), cells.end(), iip);
         }
 
-    auto const old_rows = grid_window_->GetNumberRows();
-    auto const old_cols = grid_window_->GetNumberCols();
-    auto const new_rows = grid_table_->GetRowsCount();
-    auto const new_cols = grid_table_->GetColsCount();
-
     wxGridUpdateLocker grid_update_locker(grid_window_);
     grid_window_->ClearSelection();
     grid_window_->DisableCellEditControl();
 
-    if(old_rows != new_rows || old_cols != new_cols)
+    // Check if we need to update the number of rows. Notice that Update() will
+    // take care of the columns, so we don't need to do it here.
+    auto const new_rows = grid_table_->GetRowsCount();
+    if(new_rows < old_rows)
         {
-        grid_window_->DeleteRows(0, old_rows);
-        grid_window_->DeleteCols(0, old_cols);
-        grid_window_->AppendRows(new_rows);
-        grid_window_->AppendCols(new_cols);
-        grid_table_->make_cell_number_column_read_only();
-        if(autosize_columns_)
-            {
-            grid_window_->AutoSize();
-            }
+        grid_table_->DeleteRows(new_rows, old_rows - new_rows);
+        }
+    else if(old_rows < new_rows)
+        {
+        grid_table_->AppendRows(new_rows - old_rows);
         }
+    //else: The number of rows didn't change, so keep the same ones.
 
     document().Modify(true);
     Update();



reply via email to

[Prev in Thread] Current Thread [Next in Thread]