[glom/choices_celllayout] Choices: Fix the custom tree model.



commit e51c1d8e244797a24464dcc51913713881c1fc32
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Oct 3 23:35:23 2010 +0200

    Choices: Fix the custom tree model.
    
    * glom/mode_data/datawidget/cellrenderer_dblist.cc: Use the virtual text
    column here too.
    * glom/mode_data/datawidget/treemodel_db_withextratext.cc: Call the
    ObjectBase constructor with a custom typename, as in the base class. This is
    necessary because ObjectBase is a virtual base class.

 ChangeLog                                          |   10 ++++++++++
 glom/mode_data/datawidget/cellrenderer_dblist.cc   |   17 ++++++++++++++++-
 .../datawidget/combochoiceswithtreemodel.cc        |    2 +-
 glom/mode_data/datawidget/treemodel_db.cc          |    2 --
 .../datawidget/treemodel_db_withextratext.cc       |    3 ++-
 5 files changed, 29 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 056ef8b..13606da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2010-10-03  Murray Cumming  <murrayc murrayc com>
 
+	Choices: Fix the custom tree model.
+
+	* glom/mode_data/datawidget/cellrenderer_dblist.cc: Use the virtual text 
+	column here too.
+	* glom/mode_data/datawidget/treemodel_db_withextratext.cc: Call the 
+	ObjectBase constructor with a custom typename, as in the base class. This is 
+	necessary because ObjectBase is a virtual base class.
+
+2010-10-03  Murray Cumming  <murrayc murrayc com>
+
 	Fix the previous commit.
 
 	* glom/mode_data/datawidget/treemodel_db.cc: Constructor: Actually fill
diff --git a/glom/mode_data/datawidget/cellrenderer_dblist.cc b/glom/mode_data/datawidget/cellrenderer_dblist.cc
index fa64d5a..7b9f08e 100644
--- a/glom/mode_data/datawidget/cellrenderer_dblist.cc
+++ b/glom/mode_data/datawidget/cellrenderer_dblist.cc
@@ -20,6 +20,7 @@
 
 #include "cellrenderer_dblist.h"
 #include <glom/mode_data/datawidget/cellcreation.h>
+#include <glom/mode_data/datawidget/treemodel_db_withextratext.h>
 #include <gtkmm.h>
 #include <libglom/data_structure/glomconversions.h>
 
@@ -57,10 +58,24 @@ void CellRendererDbList::set_choices_related(const Document* document, const sha
   ComboChoicesWithTreeModel::set_choices_related(document, layout_field, foreign_key_value);
 
   Glib::RefPtr<Gtk::TreeModel> model = get_choices_model();
+  if(!model)
+  {
+    std::cerr << G_STRFUNC << ": model is null" << std::endl;
+  }
 
   //Show model in the view:
   property_model() = model;
-  property_text_column() = 0; //TODO: This must be a text column, in m_refModel.
+
+  Glib::RefPtr<DbTreeModelWithExtraText> model_db = 
+    Glib::RefPtr<DbTreeModelWithExtraText>::cast_dynamic(model);
+  if(model_db)
+    property_text_column() = model_db->get_text_column();
+  else
+  {
+    std::cerr << G_STRFUNC << ": The model is not a DbTreeModelWithExtraText." << std::endl;
+    return;
+  }
+  
   property_editable() = true; //It would be useless if we couldn't edit it.
 
   //The other cells are added in on_editing_started(),
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
index e5bc8b3..51db612 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
@@ -256,7 +256,7 @@ void ComboChoicesWithTreeModel::on_cell_data(const Gtk::TreeModel::iterator& ite
   //std::cout << G_STRFUNC << ": DEBUG: model_column_index=" << model_column_index << std::endl;
   if(model_column_index >= m_db_layout_items.size())
   {
-    std::cerr << G_STRFUNC << ": model_column_index is out of range." << std::endl;
+    std::cerr << G_STRFUNC << ": model_column_index (" << model_column_index << ") is out of range. size=" << m_db_layout_items.size() << std::endl;
     return;
   }
    
diff --git a/glom/mode_data/datawidget/treemodel_db.cc b/glom/mode_data/datawidget/treemodel_db.cc
index 7fa9cf1..d86c0bc 100644
--- a/glom/mode_data/datawidget/treemodel_db.cc
+++ b/glom/mode_data/datawidget/treemodel_db.cc
@@ -179,8 +179,6 @@ DbTreeModel::DbTreeModel(const FoundSet& found_set, const type_vec_const_layout_
   m_find_mode(find_mode),
   m_stamp(1) //When the model's stamp != the iterator's stamp then that iterator is invalid and should be ignored. Also, 0=invalid
 {
-  std::cout << "debug: layout_items.size()=" << layout_items.size() << std::endl;
-
   if(!m_iface_initialized)
   {
     //GType gtype = G_OBJECT_TYPE(gobj());  //The custom GType created in the Object constructor, from the typeid.
diff --git a/glom/mode_data/datawidget/treemodel_db_withextratext.cc b/glom/mode_data/datawidget/treemodel_db_withextratext.cc
index 8b3b118..fbf0609 100644
--- a/glom/mode_data/datawidget/treemodel_db_withextratext.cc
+++ b/glom/mode_data/datawidget/treemodel_db_withextratext.cc
@@ -34,7 +34,8 @@ namespace Glom
 typedef Glib::Value<Glib::ustring> type_value_string;
 
 DbTreeModelWithExtraText::DbTreeModelWithExtraText(const FoundSet& found_set, const type_vec_const_layout_items& layout_items, bool get_records, bool find_mode, Base_DB::type_vecConstLayoutFields& fields_shown)
-: DbTreeModel(found_set, layout_items, get_records, find_mode, fields_shown)
+: Glib::ObjectBase( typeid(DbTreeModel) ), //register a custom GType.
+  DbTreeModel(found_set, layout_items, get_records, find_mode, fields_shown)
 {
   //Remember the key field details so we can use it later to get a text representation.
   if(m_column_index_key > 0 && (guint)m_column_index_key < fields_shown.size())



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