[glom] Box_Data_Calendar_Related: Use std::unique_ptr<> for the menu, instead of new and delete.



commit 1adf89459dec1b85cd036169e66ea74ff64a926e
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Feb 5 10:27:37 2016 +0100

    Box_Data_Calendar_Related: Use std::unique_ptr<> for the menu, instead of new and delete.
    
    I am not very happy with passing the raw pointer to gtkmm's
    attach_to_widget(), but that seems to be the normal use of
    unique_ptr<>::operator*() and unique_ptr<>::get(),
    as long as we don't expect the receiving API to take any
    ownership.

 glom/mode_data/box_data_calendar_related.cc |    5 ++---
 glom/mode_data/box_data_calendar_related.h  |    2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)
---
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index 552a482..218961e 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -33,8 +33,7 @@ namespace Glom
 {
 
 Box_Data_Calendar_Related::Box_Data_Calendar_Related()
-: m_pMenuPopup(nullptr),
-  m_query_column_date_field(-1)
+: m_query_column_date_field(-1)
 {
   set_size_request(400, -1); //An arbitrary default.
 
@@ -528,7 +527,7 @@ void Box_Data_Calendar_Related::setup_menu(Gtk::Widget* /* this */)
   menu->append(_("_Edit"), "context.edit");
   menu->append(_("_Layout"), "context.layout");
 
-  m_pMenuPopup = new Gtk::Menu(menu);
+  m_pMenuPopup = std::make_unique<Gtk::Menu>(menu);
   m_pMenuPopup->attach_to_widget(*this);
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
diff --git a/glom/mode_data/box_data_calendar_related.h b/glom/mode_data/box_data_calendar_related.h
index 0e697fd..84aa7c8 100644
--- a/glom/mode_data/box_data_calendar_related.h
+++ b/glom/mode_data/box_data_calendar_related.h
@@ -96,7 +96,7 @@ private:
   Gtk::Calendar m_calendar;
     
   //TODO: Avoid repeating these in so many widgets:
-  Gtk::Menu* m_pMenuPopup;
+  std::unique_ptr<Gtk::Menu> m_pMenuPopup;
   Glib::RefPtr<Gio::SimpleActionGroup> m_refActionGroup;
   Glib::RefPtr<Gio::SimpleAction> m_refContextEdit, m_refContextAdd, m_refContextDelete;
 


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