[glom] Refactored combo classes.



commit e42763bd4528aa2d63db8e14224e03ec1555954b
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Mar 23 11:02:28 2010 +0100

    Refactored combo classes.
    
    * glom/utility_widgets/comboglomchoicesbase.[h|cc]:
        Split into combochoices.[h|cc] and combochoiceswithtreemodel.[h|cc] so
        that combo_as_radio_buttons.[h|cc] doesn't need to have an unused treemodel.

 ChangeLog                                          |    8 +++
 Makefile_glom.am                                   |    6 ++-
 glom/utility_widgets/combo_as_radio_buttons.cc     |    4 +-
 glom/utility_widgets/combo_as_radio_buttons.h      |   11 +---
 glom/utility_widgets/combochoices.cc               |   56 ++++++++++++++++++++
 .../{comboglomchoicesbase.h => combochoices.h}     |   36 ++++---------
 ...choicesbase.cc => combochoiceswithtreemodel.cc} |   19 +++----
 ...omchoicesbase.h => combochoiceswithtreemodel.h} |   24 +++------
 glom/utility_widgets/comboentryglom.cc             |    6 +-
 glom/utility_widgets/comboentryglom.h              |    6 +--
 glom/utility_widgets/comboglom.cc                  |    4 +-
 glom/utility_widgets/comboglom.h                   |    6 +--
 glom/utility_widgets/datawidget.cc                 |   10 +---
 13 files changed, 112 insertions(+), 84 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a2bdb23..a9bf85c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2010-03-23  Murray Cumming  <murrayc murrayc com>
 
+    Refactored combo classes.
+
+	* glom/utility_widgets/comboglomchoicesbase.[h|cc]:
+    Split into combochoices.[h|cc] and combochoiceswithtreemodel.[h|cc] so 
+    that combo_as_radio_buttons.[h|cc] doesn't need to have an unused treemodel.
+
+2010-03-23  Murray Cumming  <murrayc murrayc com>
+
     Formatting: Choices: Add a Display as radio buttons option.
 
 	* glom/glom_developer.glade: formatting: choices: Add a Show As Radio 
diff --git a/Makefile_glom.am b/Makefile_glom.am
index 98dcf1c..a00eef6 100644
--- a/Makefile_glom.am
+++ b/Makefile_glom.am
@@ -126,8 +126,10 @@ glom_glom_SOURCES =							\
 	glom/utility_widgets/comboentryglom.h				\
 	glom/utility_widgets/comboglom.cc				\
 	glom/utility_widgets/comboglom.h				\
-	glom/utility_widgets/comboglomchoicesbase.cc			\
-	glom/utility_widgets/comboglomchoicesbase.h			\
+	glom/utility_widgets/combochoices.cc			\
+	glom/utility_widgets/combochoices.h			\
+	glom/utility_widgets/combochoiceswithtreemodel.cc			\
+	glom/utility_widgets/combochoiceswithtreemodel.h			\
 	glom/utility_widgets/combo_as_radio_buttons.cc			\
 	glom/utility_widgets/combo_as_radio_buttons.h			\
 	glom/utility_widgets/datawidget.cc				\
diff --git a/glom/utility_widgets/combo_as_radio_buttons.cc b/glom/utility_widgets/combo_as_radio_buttons.cc
index 4122749..39def7d 100644
--- a/glom/utility_widgets/combo_as_radio_buttons.cc
+++ b/glom/utility_widgets/combo_as_radio_buttons.cc
@@ -33,7 +33,7 @@ namespace Glom
 {
 
 ComboAsRadioButtons::ComboAsRadioButtons()
-: ComboGlomChoicesBase()
+: ComboChoices()
 {
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   setup_menu();
@@ -43,7 +43,7 @@ ComboAsRadioButtons::ComboAsRadioButtons()
 }
 
 ComboAsRadioButtons::ComboAsRadioButtons(const sharedptr<LayoutItem_Field>& field_second)
-: ComboGlomChoicesBase(field_second)
+: ComboChoices(field_second)
 {
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   setup_menu();
diff --git a/glom/utility_widgets/combo_as_radio_buttons.h b/glom/utility_widgets/combo_as_radio_buttons.h
index ac949f7..6958ee8 100644
--- a/glom/utility_widgets/combo_as_radio_buttons.h
+++ b/glom/utility_widgets/combo_as_radio_buttons.h
@@ -23,14 +23,7 @@
 
 #include "config.h" // For GLOM_ENABLE_CLIENT_ONLY
 
-#include <gtkmm.h>
-#include <libglom/data_structure/field.h>
-#include "comboglomchoicesbase.h"
-
-#ifdef GLOM_ENABLE_MAEMO
-#include <hildonmm/picker-button.h>
-#include <hildonmm/touch-selector-entry.h>
-#endif //GLOM_ENABLE_MAEMO
+#include <glom/utility_widgets/combochoices.h>
 
 namespace Glom
 {
@@ -43,7 +36,7 @@ class Application;
 class ComboAsRadioButtons
 : 
   public Gtk::VBox,
-  public ComboGlomChoicesBase
+  public ComboChoices
 {
 public:
 
diff --git a/glom/utility_widgets/combochoices.cc b/glom/utility_widgets/combochoices.cc
new file mode 100644
index 0000000..2228e29
--- /dev/null
+++ b/glom/utility_widgets/combochoices.cc
@@ -0,0 +1,56 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2004 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "combochoices.h"
+#include <libglom/data_structure/glomconversions.h>
+#include <glibmm/i18n.h>
+//#include <sstream> //For stringstream
+
+#include <locale>     // for locale, time_put
+#include <ctime>     // for struct tm
+#include <iostream>   // for cout, endl
+
+
+namespace Glom
+{
+
+ComboChoices::ComboChoices()
+: m_with_second(false)
+{
+  init();
+}
+
+ComboChoices::ComboChoices(const sharedptr<LayoutItem_Field>& field_second)
+: m_with_second(true),
+  m_layoutitem_second(field_second)
+{
+  init();
+}
+
+void ComboChoices::init()
+{
+}
+
+ComboChoices::~ComboChoices()
+{
+}
+
+
+} //namespace Glom
diff --git a/glom/utility_widgets/comboglomchoicesbase.h b/glom/utility_widgets/combochoices.h
similarity index 66%
copy from glom/utility_widgets/comboglomchoicesbase.h
copy to glom/utility_widgets/combochoices.h
index 6ac1bbc..93002b6 100644
--- a/glom/utility_widgets/comboglomchoicesbase.h
+++ b/glom/utility_widgets/combochoices.h
@@ -18,8 +18,8 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#ifndef GLOM_UTILITY_WIDGETS_COMBO_GLOM_CHOICESBASE_H
-#define GLOM_UTILITY_WIDGETS_COMBO_GLOM_CHOICESBASE_H
+#ifndef GLOM_UTILITY_WIDGETS_COMBO_CHOICES_H
+#define GLOM_UTILITY_WIDGETS_COMBO_CHOICES_H
 
 #include <gtkmm.h>
 #include <libglom/data_structure/field.h>
@@ -28,41 +28,27 @@
 namespace Glom
 {
 
-class ComboGlomChoicesBase : public LayoutWidgetField
+/** A polymorphic base class for all the combo-like widgets.
+ */
+class ComboChoices : public LayoutWidgetField
 {
 public:
   ///You must call set_layout_item() to specify the field type and formatting of the main column.
-  explicit ComboGlomChoicesBase();
+  explicit ComboChoices();
 
   ///You must call set_layout_item() to specify the field type and formatting of the main column.
-  explicit ComboGlomChoicesBase(const sharedptr<LayoutItem_Field>& field_second);
+  explicit ComboChoices(const sharedptr<LayoutItem_Field>& field_second);
 
-  virtual ~ComboGlomChoicesBase();
+  virtual ~ComboChoices();
 
-  virtual void set_choices(const FieldFormatting::type_list_values& list_values);
+  virtual void set_choices(const FieldFormatting::type_list_values& list_values) = 0;
 
   typedef std::list< std::pair<Gnome::Gda::Value, Gnome::Gda::Value> > type_list_values_with_second;
-  virtual void set_choices_with_second(const type_list_values_with_second& list_values);
+  virtual void set_choices_with_second(const type_list_values_with_second& list_values) = 0;
 
 protected:
   void init();
 
-  //Tree model columns:
-  class ModelColumns : public Gtk::TreeModel::ColumnRecord
-  {
-  public:
-
-    ModelColumns()
-    { add(m_col_first); add(m_col_second); }
-
-    Gtk::TreeModelColumn<Glib::ustring> m_col_first; //The data to choose - this must be text.
-    Gtk::TreeModelColumn<Glib::ustring> m_col_second;
-  };
-
-  ModelColumns m_Columns;
-
-  Glib::RefPtr<Gtk::ListStore> m_refModel;
-
   bool m_with_second;
   sharedptr<const LayoutItem_Field> m_layoutitem_second;
   //Gnome::Gda::Value m_value; //The last-stored value. We have this because the displayed value might be unparseable.
@@ -70,5 +56,5 @@ protected:
 
 } //namespace Glom
 
-#endif //GLOM_UTILITY_WIDGETS_COMBO_GLOM_CHOICESBASE_H
+#endif //GLOM_UTILITY_WIDGETS_COMBO_CHOICES_H
 
diff --git a/glom/utility_widgets/comboglomchoicesbase.cc b/glom/utility_widgets/combochoiceswithtreemodel.cc
similarity index 82%
rename from glom/utility_widgets/comboglomchoicesbase.cc
rename to glom/utility_widgets/combochoiceswithtreemodel.cc
index b4bdac8..00545c7 100644
--- a/glom/utility_widgets/comboglomchoicesbase.cc
+++ b/glom/utility_widgets/combochoiceswithtreemodel.cc
@@ -18,7 +18,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#include "comboglomchoicesbase.h"
+#include "combochoiceswithtreemodel.h"
 #include <libglom/data_structure/glomconversions.h>
 #include <glibmm/i18n.h>
 //#include <sstream> //For stringstream
@@ -31,29 +31,28 @@
 namespace Glom
 {
 
-ComboGlomChoicesBase::ComboGlomChoicesBase()
-: m_with_second(false)
+ComboChoicesWithTreeModel::ComboChoicesWithTreeModel()
 {
   init();
 }
 
-ComboGlomChoicesBase::ComboGlomChoicesBase(const sharedptr<LayoutItem_Field>& field_second)
-: m_with_second(true),
-  m_layoutitem_second(field_second)
+ComboChoicesWithTreeModel::ComboChoicesWithTreeModel(const sharedptr<LayoutItem_Field>& field_second)
+: ComboChoices(field_second)
 {
   init();
 }
 
-void ComboGlomChoicesBase::init()
+void ComboChoicesWithTreeModel::init()
 {
+  ComboChoices::init();
   m_refModel = Gtk::ListStore::create(m_Columns);
 }
 
-ComboGlomChoicesBase::~ComboGlomChoicesBase()
+ComboChoicesWithTreeModel::~ComboChoicesWithTreeModel()
 {
 }
 
-void ComboGlomChoicesBase::set_choices_with_second(const type_list_values_with_second& list_values)
+void ComboChoicesWithTreeModel::set_choices_with_second(const type_list_values_with_second& list_values)
 {
   m_refModel->clear();
 
@@ -76,7 +75,7 @@ void ComboGlomChoicesBase::set_choices_with_second(const type_list_values_with_s
 }
 
 
-void ComboGlomChoicesBase::set_choices(const FieldFormatting::type_list_values& list_values)
+void ComboChoicesWithTreeModel::set_choices(const FieldFormatting::type_list_values& list_values)
 {
   m_refModel->clear();
 
diff --git a/glom/utility_widgets/comboglomchoicesbase.h b/glom/utility_widgets/combochoiceswithtreemodel.h
similarity index 67%
rename from glom/utility_widgets/comboglomchoicesbase.h
rename to glom/utility_widgets/combochoiceswithtreemodel.h
index 6ac1bbc..ce886bd 100644
--- a/glom/utility_widgets/comboglomchoicesbase.h
+++ b/glom/utility_widgets/combochoiceswithtreemodel.h
@@ -18,30 +18,26 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#ifndef GLOM_UTILITY_WIDGETS_COMBO_GLOM_CHOICESBASE_H
-#define GLOM_UTILITY_WIDGETS_COMBO_GLOM_CHOICESBASE_H
+#ifndef GLOM_UTILITY_WIDGETS_COMBO_CHOICES_WITH_TREE_MODEL_H
+#define GLOM_UTILITY_WIDGETS_COMBO_CHOICES_WITH_TREE_MODEL_H
 
-#include <gtkmm.h>
-#include <libglom/data_structure/field.h>
-#include "layoutwidgetfield.h"
+#include <glom/utility_widgets/combochoices.h>
 
 namespace Glom
 {
 
-class ComboGlomChoicesBase : public LayoutWidgetField
+class ComboChoicesWithTreeModel : public ComboChoices
 {
 public:
   ///You must call set_layout_item() to specify the field type and formatting of the main column.
-  explicit ComboGlomChoicesBase();
+  explicit ComboChoicesWithTreeModel();
 
   ///You must call set_layout_item() to specify the field type and formatting of the main column.
-  explicit ComboGlomChoicesBase(const sharedptr<LayoutItem_Field>& field_second);
+  explicit ComboChoicesWithTreeModel(const sharedptr<LayoutItem_Field>& field_second);
 
-  virtual ~ComboGlomChoicesBase();
+  virtual ~ComboChoicesWithTreeModel();
 
   virtual void set_choices(const FieldFormatting::type_list_values& list_values);
-
-  typedef std::list< std::pair<Gnome::Gda::Value, Gnome::Gda::Value> > type_list_values_with_second;
   virtual void set_choices_with_second(const type_list_values_with_second& list_values);
 
 protected:
@@ -62,13 +58,9 @@ protected:
   ModelColumns m_Columns;
 
   Glib::RefPtr<Gtk::ListStore> m_refModel;
-
-  bool m_with_second;
-  sharedptr<const LayoutItem_Field> m_layoutitem_second;
-  //Gnome::Gda::Value m_value; //The last-stored value. We have this because the displayed value might be unparseable.
 };
 
 } //namespace Glom
 
-#endif //GLOM_UTILITY_WIDGETS_COMBO_GLOM_CHOICESBASE_H
+#endif //GLOM_UTILITY_WIDGETS_COMBO_CHOICES_WITH_TREE_MODEL_H
 
diff --git a/glom/utility_widgets/comboentryglom.cc b/glom/utility_widgets/comboentryglom.cc
index 1b8a7b0..abee0cb 100644
--- a/glom/utility_widgets/comboentryglom.cc
+++ b/glom/utility_widgets/comboentryglom.cc
@@ -39,7 +39,7 @@ namespace Glom
 {
 
 ComboEntryGlom::ComboEntryGlom()
-: ComboGlomChoicesBase()
+: ComboChoicesWithTreeModel()
 {
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   setup_menu();
@@ -49,7 +49,7 @@ ComboEntryGlom::ComboEntryGlom()
 }
 
 ComboEntryGlom::ComboEntryGlom(const sharedptr<LayoutItem_Field>& field_second)
-: ComboGlomChoicesBase(field_second)
+: ComboChoicesWithTreeModel(field_second)
 {
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   setup_menu();
@@ -154,7 +154,7 @@ ComboEntryGlom::~ComboEntryGlom()
 void ComboEntryGlom::set_layout_item(const sharedptr<LayoutItem>& layout_item, const Glib::ustring& table_name)
 {
   //Call base class:
-  ComboGlomChoicesBase::set_layout_item(layout_item, table_name);
+  ComboChoicesWithTreeModel::set_layout_item(layout_item, table_name);
 
   if(!layout_item)
     return;
diff --git a/glom/utility_widgets/comboentryglom.h b/glom/utility_widgets/comboentryglom.h
index 9e874d8..7b687cc 100644
--- a/glom/utility_widgets/comboentryglom.h
+++ b/glom/utility_widgets/comboentryglom.h
@@ -23,9 +23,7 @@
 
 #include "config.h" // For GLOM_ENABLE_CLIENT_ONLY
 
-#include <gtkmm.h>
-#include <libglom/data_structure/field.h>
-#include "comboglomchoicesbase.h"
+#include <glom/utility_widgets/combochoiceswithtreemodel.h>
 
 #ifdef GLOM_ENABLE_MAEMO
 #include <hildonmm/picker-button.h>
@@ -48,7 +46,7 @@ class ComboEntryGlom
 #else
   public Hildon::PickerButton,
 #endif
-  public ComboGlomChoicesBase
+  public ComboChoicesWithTreeModel
 {
 public:
   ///You must call set_layout_item() to specify the field type and formatting of the main column.
diff --git a/glom/utility_widgets/comboglom.cc b/glom/utility_widgets/comboglom.cc
index 48a4d87..711f29c 100644
--- a/glom/utility_widgets/comboglom.cc
+++ b/glom/utility_widgets/comboglom.cc
@@ -35,7 +35,7 @@ namespace Glom
 {
 
 ComboGlom::ComboGlom()
-: ComboGlomChoicesBase()
+: ComboChoicesWithTreeModel()
 {
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   setup_menu();
@@ -45,7 +45,7 @@ ComboGlom::ComboGlom()
 }
 
 ComboGlom::ComboGlom(const sharedptr<LayoutItem_Field>& field_second)
-: ComboGlomChoicesBase(field_second)
+: ComboChoicesWithTreeModel(field_second)
 {
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   setup_menu();
diff --git a/glom/utility_widgets/comboglom.h b/glom/utility_widgets/comboglom.h
index 0cf34e4..8e81eb2 100644
--- a/glom/utility_widgets/comboglom.h
+++ b/glom/utility_widgets/comboglom.h
@@ -23,9 +23,7 @@
 
 #include "config.h" // For GLOM_ENABLE_CLIENT_ONLY
 
-#include <gtkmm.h>
-#include <libglom/data_structure/field.h>
-#include "comboglomchoicesbase.h"
+#include <glom/utility_widgets/combochoiceswithtreemodel.h>
 
 #ifdef GLOM_ENABLE_MAEMO
 #include <hildonmm/picker-button.h>
@@ -47,7 +45,7 @@ class ComboGlom
 #else
   public Hildon::PickerButton,
 #endif
-  public ComboGlomChoicesBase
+  public ComboChoicesWithTreeModel
 {
 public:
 
diff --git a/glom/utility_widgets/datawidget.cc b/glom/utility_widgets/datawidget.cc
index 281b3bf..bcb83ae 100644
--- a/glom/utility_widgets/datawidget.cc
+++ b/glom/utility_widgets/datawidget.cc
@@ -46,16 +46,13 @@
 namespace Glom
 {
 
-static ComboGlomChoicesBase* create_combo_widget_for_field(const sharedptr<LayoutItem_Field>& field, const sharedptr<LayoutItem_Field>& layout_item_second = sharedptr<LayoutItem_Field>())
+static ComboChoices* create_combo_widget_for_field(const sharedptr<LayoutItem_Field>& field, const sharedptr<LayoutItem_Field>& layout_item_second = sharedptr<LayoutItem_Field>())
 {
-  std::cout << "create_combo_widget_for_field(): field=" << field->get_name() << std::endl;
-  ComboGlomChoicesBase* result = 0;
+  ComboChoices* result = 0;
   bool as_radio_buttons = false; //TODO: Use this.
   const bool restricted = field->get_formatting_used().get_choices_restricted(as_radio_buttons);
   if(restricted)
   {
-    std::cout << "  restricted" << std::endl;
-  
     if(as_radio_buttons)
       result = Gtk::manage(new ComboAsRadioButtons(layout_item_second));
     else
@@ -119,8 +116,7 @@ DataWidget::DataWidget(const sharedptr<LayoutItem_Field>& field, const Glib::ust
     //Use a Combo if there is a drop-down of choices (A "value list"), else an Entry:
     if(field->get_formatting_used().get_has_choices())
     {
-      std::cout << "DEBUG: has choices" << std::endl;
-      ComboGlomChoicesBase* combo = create_combo_widget_for_field(field);
+      ComboChoices* combo = create_combo_widget_for_field(field);
 
       if(field->get_formatting_used().get_has_custom_choices())
       {



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