lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 193e804 01/46: Refactor census view to enable


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 193e804 01/46: Refactor census view to enable several implementations
Date: Wed, 22 Jul 2020 11:05:08 -0400 (EDT)

branch: master
commit 193e804a3da73a05f0e93c2d1f30cf975edadd2f
Author: Ilya Sinitsyn <isinitsyn@tt-solutions.com>
Commit: Vadim Zeitlin <vadim@tt-solutions.com>

    Refactor census view to enable several implementations
    
    Extract all code specific to wxDataViewCtrl to a new CensusDVCView class,
    keeping only the code independent of the control being used by the view
    in the base CensusView class, in order to allow adding a wxGrid-based
    implementation in the upcoming commits.
    
    CensusDVCView function implementations was not sorted properly to
    decrement changes count and be sure that real logic changes was not
    made at all.
---
 census_document.cpp |   8 ++--
 census_document.hpp |  18 +++++++--
 census_view.cpp     |  56 +++++++++++++++------------
 census_view.hpp     | 108 ++++++++++++++++++++++++++++++++++------------------
 skeleton.cpp        |   4 +-
 5 files changed, 124 insertions(+), 70 deletions(-)

diff --git a/census_document.cpp b/census_document.cpp
index 7f79c67..166bd6e 100644
--- a/census_document.cpp
+++ b/census_document.cpp
@@ -33,13 +33,13 @@
 
 #include <fstream>
 
-IMPLEMENT_DYNAMIC_CLASS(CensusDocument, wxDocument)
+IMPLEMENT_DYNAMIC_CLASS(CensusDVCDocument, CensusDocument)
 
-wxDataViewCtrl& CensusDocument::PredominantViewWindow() const
+wxDataViewCtrl& CensusDVCDocument::PredominantViewWindow() const
 {
-    return ::PredominantViewWindow<CensusView,wxDataViewCtrl>
+    return ::PredominantViewWindow<CensusDVCView,wxDataViewCtrl>
         (*this
-        ,&CensusView::list_window_
+        ,&CensusDVCView::list_window_
         );
 }
 
diff --git a/census_document.hpp b/census_document.hpp
index 7b934d0..889b3ba 100644
--- a/census_document.hpp
+++ b/census_document.hpp
@@ -44,16 +44,28 @@ class CensusDocument
     CensusDocument(CensusDocument const&) = delete;
     CensusDocument& operator=(CensusDocument const&) = delete;
 
-    wxDataViewCtrl& PredominantViewWindow() const;
-
     // wxDocument overrides.
     bool OnCreate(wxString const& filename, long int flags) override;
     bool DoOpenDocument(wxString const& filename) override;
     bool DoSaveDocument(wxString const& filename) override;
 
     multiple_cell_document doc_;
+};
+
+class CensusDVCDocument final
+    :public CensusDocument
+{
+  public:
+    CensusDVCDocument() = default;
+    ~CensusDVCDocument() override = default;
+
+  private:
+    CensusDVCDocument(CensusDVCDocument const&) = delete;
+    CensusDVCDocument& operator=(CensusDVCDocument const&) = delete;
+
+    wxDataViewCtrl& PredominantViewWindow() const;
 
-    DECLARE_DYNAMIC_CLASS(CensusDocument)
+    DECLARE_DYNAMIC_CLASS(CensusDVCDocument)
 };
 
 #endif // census_document_hpp
diff --git a/census_view.cpp b/census_view.cpp
index 961c1cf..eb83df1 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -818,7 +818,7 @@ class CensusViewDataViewModel : public 
wxDataViewIndexListModel
     // Cell serial number: always shown in first column.
     static int const Col_CellNum = 0;
 
-    CensusViewDataViewModel(CensusView& view)
+    CensusViewDataViewModel(CensusDVCView& view)
         :view_ {view}
     {
     }
@@ -837,7 +837,7 @@ class CensusViewDataViewModel : public 
wxDataViewIndexListModel
   private:
     std::vector<std::string> const& all_headers() const;
 
-    CensusView& view_;
+    CensusDVCView& view_;
 };
 
 void CensusViewDataViewModel::GetValueByRow
@@ -934,11 +934,7 @@ inline std::vector<std::string> const& 
CensusViewDataViewModel::all_headers() co
 
 // class CensusView
 
-IMPLEMENT_DYNAMIC_CLASS(CensusView, ViewEx)
-
 BEGIN_EVENT_TABLE(CensusView, ViewEx)
-    EVT_DATAVIEW_ITEM_CONTEXT_MENU (wxID_ANY    ,CensusView::UponRightClick    
         )
-    EVT_DATAVIEW_ITEM_VALUE_CHANGED(wxID_ANY    ,CensusView::UponValueChanged  
         )
     EVT_MENU(XRCID("edit_cell"                 ),CensusView::UponEditCell      
         )
     EVT_MENU(XRCID("edit_class"                ),CensusView::UponEditClass     
         )
     EVT_MENU(XRCID("edit_case"                 ),CensusView::UponEditCase      
         )
@@ -957,11 +953,7 @@ BEGIN_EVENT_TABLE(CensusView, ViewEx)
     EVT_MENU(XRCID("delete_cells"              ),CensusView::UponDeleteCells   
         )
     EVT_MENU(XRCID("column_width_varying"      
),CensusView::UponColumnWidthVarying     )
     EVT_MENU(XRCID("column_width_fixed"        
),CensusView::UponColumnWidthFixed       )
-    EVT_UPDATE_UI(XRCID("edit_cell"            
),CensusView::UponUpdateSingleSelection  )
-    EVT_UPDATE_UI(XRCID("edit_class"           
),CensusView::UponUpdateSingleSelection  )
     EVT_UPDATE_UI(XRCID("edit_case"            
),CensusView::UponUpdateAlwaysEnabled    )
-    EVT_UPDATE_UI(XRCID("run_cell"             
),CensusView::UponUpdateSingleSelection  )
-    EVT_UPDATE_UI(XRCID("run_class"            
),CensusView::UponUpdateSingleSelection  )
     EVT_UPDATE_UI(XRCID("run_case"             
),CensusView::UponUpdateAlwaysEnabled    )
     EVT_UPDATE_UI(XRCID("print_case"           
),CensusView::UponUpdateAlwaysEnabled    )
     EVT_UPDATE_UI(XRCID("print_case_to_disk"   
),CensusView::UponUpdateAlwaysEnabled    )
@@ -982,9 +974,25 @@ BEGIN_EVENT_TABLE(CensusView, ViewEx)
     EVT_UPDATE_UI(XRCID("print_pdf"            
),CensusView::UponUpdateAlwaysDisabled   )
 END_EVENT_TABLE()
 
+IMPLEMENT_DYNAMIC_CLASS(CensusDVCView, CensusView)
+
+BEGIN_EVENT_TABLE(CensusDVCView, CensusView)
+    EVT_DATAVIEW_ITEM_CONTEXT_MENU (wxID_ANY    ,CensusDVCView::UponRightClick 
          )
+    EVT_DATAVIEW_ITEM_VALUE_CHANGED(wxID_ANY    
,CensusDVCView::UponValueChanged         )
+    EVT_UPDATE_UI(XRCID("edit_cell"            
),CensusDVCView::UponUpdateSingleSelection)
+    EVT_UPDATE_UI(XRCID("edit_class"           
),CensusDVCView::UponUpdateSingleSelection)
+    EVT_UPDATE_UI(XRCID("run_cell"             
),CensusDVCView::UponUpdateSingleSelection)
+    EVT_UPDATE_UI(XRCID("run_class"            
),CensusDVCView::UponUpdateSingleSelection)
+END_EVENT_TABLE()
+
 CensusView::CensusView()
     :ViewEx            {}
     ,autosize_columns_ {false}
+{
+}
+
+CensusDVCView::CensusDVCView()
+    :CensusView        {}
     ,list_window_      {nullptr}
     ,list_model_       {new(wx) CensusViewDataViewModel(*this)}
 {
@@ -1080,7 +1088,7 @@ bool 
CensusView::column_value_varies_across_cells(std::string const& header) con
     return false;
 }
 
-wxWindow* CensusView::CreateChildWindow()
+wxWindow* CensusDVCView::CreateChildWindow()
 {
     list_window_ = new(wx) wxDataViewCtrl
         (GetFrame()
@@ -1120,7 +1128,7 @@ oenum_mvc_dv_rc CensusView::edit_parameters
         );
 }
 
-int CensusView::selected_row()
+int CensusDVCView::selected_row()
 {
     int row = list_model_->GetRow(list_window_->GetSelection());
     LMI_ASSERT(0 <= row && row < bourn_cast<int>(list_model_->GetCount()));
@@ -1268,7 +1276,7 @@ void CensusView::apply_changes
         }
 }
 
-void CensusView::update_visible_columns()
+void CensusDVCView::update_visible_columns()
 {
     int width = autosize_columns_ ? wxCOL_WIDTH_AUTOSIZE : wxCOL_WIDTH_DEFAULT;
 
@@ -1389,7 +1397,7 @@ void CensusView::UponEditCase(wxCommandEvent&)
 /// Make each nonfrozen column wide enough to display its widest entry,
 /// ignoring column headers.
 
-void CensusView::UponColumnWidthVarying(wxCommandEvent&)
+void CensusDVCView::UponColumnWidthVarying(wxCommandEvent&)
 {
     autosize_columns_ = true;
 
@@ -1403,7 +1411,7 @@ void CensusView::UponColumnWidthVarying(wxCommandEvent&)
 
 /// Shrink all nonfrozen columns to default width.
 
-void CensusView::UponColumnWidthFixed(wxCommandEvent&)
+void CensusDVCView::UponColumnWidthFixed(wxCommandEvent&)
 {
     autosize_columns_ = false;
 
@@ -1415,7 +1423,7 @@ void CensusView::UponColumnWidthFixed(wxCommandEvent&)
     Update();
 }
 
-void CensusView::UponRightClick(wxDataViewEvent& e)
+void CensusDVCView::UponRightClick(wxDataViewEvent& e)
 {
     if(e.GetEventObject() != list_window_)
         {
@@ -1431,7 +1439,7 @@ void CensusView::UponRightClick(wxDataViewEvent& e)
     delete census_menu;
 }
 
-void CensusView::UponValueChanged(wxDataViewEvent&)
+void CensusDVCView::UponValueChanged(wxDataViewEvent&)
 {
     Timer timer;
     Update();
@@ -1448,13 +1456,13 @@ void 
CensusView::UponUpdateAlwaysEnabled(wxUpdateUIEvent& e)
     e.Enable(true);
 }
 
-void CensusView::UponUpdateSingleSelection(wxUpdateUIEvent& e)
+void CensusDVCView::UponUpdateSingleSelection(wxUpdateUIEvent& e)
 {
     bool const is_single_sel = list_window_->GetSelection().IsOk();
     e.Enable(is_single_sel);
 }
 
-void CensusView::UponUpdateNonemptySelection(wxUpdateUIEvent& e)
+void CensusDVCView::UponUpdateNonemptySelection(wxUpdateUIEvent& e)
 {
     wxDataViewItemArray selection;
     e.Enable(0 < list_window_->GetSelections(selection));
@@ -1475,7 +1483,7 @@ void 
CensusView::UponUpdateNonemptySelection(wxUpdateUIEvent& e)
 /// because if "IssueAge" varies, then so must either "DateOfBirth"
 /// or "EffectiveDate".
 
-void CensusView::UponUpdateColumnValuesVary(wxUpdateUIEvent& e)
+void CensusDVCView::UponUpdateColumnValuesVary(wxUpdateUIEvent& e)
 {
     static const std::string dob_header = 
insert_spaces_between_words("UseDOB");
     int const n_cols = bourn_cast<int>(list_window_->GetColumnCount());
@@ -1495,7 +1503,7 @@ void 
CensusView::UponUpdateColumnValuesVary(wxUpdateUIEvent& e)
 /// Similarly, if an old employee class is no longer used, remove it; and
 ///  if a new one comes into use, display it.
 
-void CensusView::Update()
+void CensusDVCView::Update()
 {
     LMI_ASSERT(list_model_->GetCount() == cell_parms().size());
 
@@ -1570,7 +1578,7 @@ bool CensusView::DoAllCells(mcenum_emission emission)
     return true;
 }
 
-void CensusView::UponAddCell(wxCommandEvent&)
+void CensusDVCView::UponAddCell(wxCommandEvent&)
 {
     wxBusyCursor reverie;
     Timer timer;
@@ -1589,7 +1597,7 @@ void CensusView::UponAddCell(wxCommandEvent&)
     status() << "Add: " << timer.stop().elapsed_msec_str() << std::flush;
 }
 
-void CensusView::UponDeleteCells(wxCommandEvent&)
+void CensusDVCView::UponDeleteCells(wxCommandEvent&)
 {
     int n_items = bourn_cast<int>(list_model_->GetCount());
     wxDataViewItemArray selection;
@@ -1707,7 +1715,7 @@ void CensusView::UponRunCaseToGroupQuote(wxCommandEvent&)
 /// file are assumed to represent user intention). In this case,
 /// pasted data is appended to the cells that were already present.
 
-void CensusView::UponPasteCensus(wxCommandEvent&)
+void CensusDVCView::UponPasteCensus(wxCommandEvent&)
 {
     std::string const census_data = ClipboardEx::GetText();
 
diff --git a/census_view.hpp b/census_view.hpp
index 5566aa4..a826c2d 100644
--- a/census_view.hpp
+++ b/census_view.hpp
@@ -38,17 +38,10 @@
 #include <vector>
 
 class CensusDocument;
-class CensusViewDataViewModel;
 
-class WXDLLIMPEXP_FWD_ADV wxDataViewEvent;
-class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
-
-class CensusView final
+class CensusView
     :public ViewEx
 {
-    friend class CensusDocument;
-    friend class CensusViewDataViewModel;
-
   public:
     CensusView();
 
@@ -56,43 +49,40 @@ class CensusView final
     CensusView(CensusView const&) = delete;
     CensusView& operator=(CensusView const&) = delete;
 
-    void update_visible_columns();
+  protected:
+    virtual void update_visible_columns() = 0;
 
     CensusDocument& document() const;
 
     // ViewEx required implementation.
-    wxWindow* CreateChildWindow() override;
     char const* icon_xrc_resource   () const override;
     char const* menubar_xrc_resource() const override;
 
     // Event handlers, in event-table order (reflecting GUI order)
-    void UponRightClick             (wxDataViewEvent&);
-    void UponValueChanged           (wxDataViewEvent&);
-    void UponEditCell               (wxCommandEvent&);
-    void UponEditClass              (wxCommandEvent&);
-    void UponEditCase               (wxCommandEvent&);
-    void UponRunCell                (wxCommandEvent&);
-    void UponRunCase                (wxCommandEvent&);
-    void UponPrintCase              (wxCommandEvent&);
-    void UponPrintCaseToDisk        (wxCommandEvent&);
-    void UponRunCaseToSpreadsheet   (wxCommandEvent&);
-    void UponRunCaseToGroupRoster   (wxCommandEvent&);
-    void UponRunCaseToGroupQuote    (wxCommandEvent&);
-    void UponCopyCensus             (wxCommandEvent&);
-    void UponPasteCensus            (wxCommandEvent&);
-    void UponAddCell                (wxCommandEvent&);
-    void UponDeleteCells            (wxCommandEvent&);
-    void UponColumnWidthVarying     (wxCommandEvent&);
-    void UponColumnWidthFixed       (wxCommandEvent&);
-    void UponUpdateAlwaysDisabled   (wxUpdateUIEvent&);
-    void UponUpdateAlwaysEnabled    (wxUpdateUIEvent&);
-    void UponUpdateSingleSelection  (wxUpdateUIEvent&);
-    void UponUpdateNonemptySelection(wxUpdateUIEvent&);
-    void UponUpdateColumnValuesVary (wxUpdateUIEvent&);
+    void         UponEditCell               (wxCommandEvent&);
+    void         UponEditClass              (wxCommandEvent&);
+    void         UponEditCase               (wxCommandEvent&);
+    void         UponRunCell                (wxCommandEvent&);
+    void         UponRunCase                (wxCommandEvent&);
+    void         UponPrintCase              (wxCommandEvent&);
+    void         UponPrintCaseToDisk        (wxCommandEvent&);
+    void         UponRunCaseToSpreadsheet   (wxCommandEvent&);
+    void         UponRunCaseToGroupRoster   (wxCommandEvent&);
+    void         UponRunCaseToGroupQuote    (wxCommandEvent&);
+    void         UponCopyCensus             (wxCommandEvent&);
+    virtual void UponPasteCensus            (wxCommandEvent&) = 0;
+    virtual void UponAddCell                (wxCommandEvent&) = 0;
+    virtual void UponDeleteCells            (wxCommandEvent&) = 0;
+    virtual void UponColumnWidthVarying     (wxCommandEvent&) = 0;
+    virtual void UponColumnWidthFixed       (wxCommandEvent&) = 0;
+    void         UponUpdateAlwaysDisabled   (wxUpdateUIEvent&);
+    void         UponUpdateAlwaysEnabled    (wxUpdateUIEvent&);
+    virtual void UponUpdateNonemptySelection(wxUpdateUIEvent&) = 0;
+    virtual void UponUpdateColumnValuesVary (wxUpdateUIEvent&) = 0;
 
     bool DoAllCells(mcenum_emission);
 
-    void Update();
+    virtual void Update() = 0;
     void ViewOneCell(int);
     void ViewComposite();
 
@@ -121,7 +111,7 @@ class CensusView final
         ,std::string const& title
         );
 
-    int selected_row();
+    virtual int selected_row() = 0;
 
     void update_class_names();
 
@@ -131,10 +121,54 @@ class CensusView final
 
     std::shared_ptr<Ledger const> composite_ledger_;
 
-    wxDataViewCtrl* list_window_;
+    DECLARE_EVENT_TABLE()
+};
+
+class CensusDVCDocument;
+class CensusViewDataViewModel;
+
+class WXDLLIMPEXP_FWD_ADV wxDataViewEvent;
+class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
+
+class CensusDVCView final
+    :public CensusView
+{
+    friend class CensusDVCDocument;
+    friend class CensusViewDataViewModel;
+
+  public:
+    CensusDVCView();
+
+  private:
+    CensusDVCView(CensusDVCView const&) = delete;
+    CensusDVCView& operator=(CensusDVCView const&) = delete;
+
+    void update_visible_columns() override;
+
+    // ViewEx required implementation.
+    wxWindow* CreateChildWindow() override;
+
+    // Event handlers, in event-table order (reflecting GUI order)
+
+    void UponRightClick             (wxDataViewEvent&);
+    void UponValueChanged           (wxDataViewEvent&);
+    void UponPasteCensus            (wxCommandEvent&) override;
+    void UponAddCell                (wxCommandEvent&) override;
+    void UponDeleteCells            (wxCommandEvent&) override;
+    void UponColumnWidthVarying     (wxCommandEvent&) override;
+    void UponColumnWidthFixed       (wxCommandEvent&) override;
+    void UponUpdateSingleSelection  (wxUpdateUIEvent&);
+    void UponUpdateNonemptySelection(wxUpdateUIEvent&) override;
+    void UponUpdateColumnValuesVary (wxUpdateUIEvent&) override;
+
+    void Update() override;
+
+    int selected_row() override;
+
+    wxDataViewCtrl* list_window_ {nullptr};
     wxObjectDataPtr<CensusViewDataViewModel> list_model_;
 
-    DECLARE_DYNAMIC_CLASS(CensusView)
+    DECLARE_DYNAMIC_CLASS(CensusDVCView)
     DECLARE_EVENT_TABLE()
 };
 
diff --git a/skeleton.cpp b/skeleton.cpp
index 51beef5..7aa70c2 100644
--- a/skeleton.cpp
+++ b/skeleton.cpp
@@ -305,8 +305,8 @@ void Skeleton::InitDocManager()
         ,"cns"
         ,"Census document"
         ,"Census view"
-        ,CLASSINFO(CensusDocument)
-        ,CLASSINFO(CensusView)
+        ,CLASSINFO(CensusDVCDocument)
+        ,CLASSINFO(CensusDVCView)
         );
 
     new(wx) wxDocTemplate



reply via email to

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