[glom] Choices combo widgets: Initial work to make the model generic.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Choices combo widgets: Initial work to make the model generic.
- Date: Sat, 11 Sep 2010 11:44:15 +0000 (UTC)
commit e67c2d0ad4f8882dd74357d477bce6b004cfc6d2
Author: Murray Cumming <murrayc murrayc com>
Date: Sat Sep 11 13:27:53 2010 +0200
Choices combo widgets: Initial work to make the model generic.
* glom/mode_data/datawidget/combochoiceswithtreemodel.[h|cc]: Change
m_refModel to a generic TreeModel, make it private ,and add a
get_choices_model() accessor, as a step to optionally using a db-based
treemodel like Db_AddDel.
* glom/mode_data/datawidget/combo.cc:
* glom/mode_data/datawidget/comboentry.cc:
* glom/mode_data/db_adddel/cellrenderer_dblist.cc: Adapted.
ChangeLog | 12 ++++++++++
glom/mode_data/datawidget/combo.cc | 5 ++-
.../datawidget/combochoiceswithtreemodel.cc | 23 ++++++++++++++++++-
.../datawidget/combochoiceswithtreemodel.h | 7 ++++-
glom/mode_data/datawidget/comboentry.cc | 2 +-
glom/mode_data/db_adddel/cellrenderer_dblist.cc | 2 +-
6 files changed, 43 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c0f1037..98d1f0e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-09-11 Murray Cumming <murrayc murrayc com>
+
+ Choices combo widgets: Initial work to make the model generic.
+
+ * glom/mode_data/datawidget/combochoiceswithtreemodel.[h|cc]: Change
+ m_refModel to a generic TreeModel, make it private ,and add a
+ get_choices_model() accessor, as a step to optionally using a db-based
+ treemodel like Db_AddDel.
+ * glom/mode_data/datawidget/combo.cc:
+ * glom/mode_data/datawidget/comboentry.cc:
+ * glom/mode_data/db_adddel/cellrenderer_dblist.cc: Adapted.
+
2010-09-10 Murray Cumming <murrayc murrayc com>
Moved the Db_AddDel code.
diff --git a/glom/mode_data/datawidget/combo.cc b/glom/mode_data/datawidget/combo.cc
index 3097534..7e5de3a 100644
--- a/glom/mode_data/datawidget/combo.cc
+++ b/glom/mode_data/datawidget/combo.cc
@@ -75,7 +75,7 @@ void ComboGlom::create_model(guint columns_count)
ComboChoicesWithTreeModel::create_model(columns_count);
//Show the model in the view:
- set_model(m_refModel);
+ set_model(get_choices_model());
clear();
@@ -164,7 +164,8 @@ void ComboGlom::set_text(const Glib::ustring& text)
{
m_old_text = text;
- for(Gtk::TreeModel::iterator iter = m_refModel->children().begin(); iter != m_refModel->children().end(); ++iter)
+ Glib::RefPtr<Gtk::TreeModel> model = get_choices_model();
+ for(Gtk::TreeModel::iterator iter = model->children().begin(); iter != model->children().end(); ++iter)
{
const Gtk::TreeModel::Row row = *iter;
Glib::ustring this_text;
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
index 36de73c..b48a556 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
@@ -115,9 +115,16 @@ void ComboChoicesWithTreeModel::set_choices_with_second(const type_list_values_w
if(layout_choice_extra)
extra_fields = layout_choice_extra->get_items_recursive();
+ Glib::RefPtr<Gtk::ListStore> list_store = Glib::RefPtr<Gtk::ListStore>::cast_dynamic(m_refModel);
+ if(!list_store)
+ {
+ std::cerr << G_STRFUNC << ": list_store is null." << std::endl;
+ return;
+ }
+
for(type_list_values_with_second::const_iterator iter = list_values.begin(); iter != list_values.end(); ++iter)
{
- Gtk::TreeModel::iterator iterTree = m_refModel->append();
+ Gtk::TreeModel::iterator iterTree = list_store->append();
Gtk::TreeModel::Row row = *iterTree;
if(layout_choice_first)
@@ -163,9 +170,16 @@ void ComboChoicesWithTreeModel::set_choices(const FieldFormatting::type_list_val
{
create_model(1);
+ Glib::RefPtr<Gtk::ListStore> list_store = Glib::RefPtr<Gtk::ListStore>::cast_dynamic(m_refModel);
+ if(!list_store)
+ {
+ std::cerr << G_STRFUNC << ": list_store is null." << std::endl;
+ return;
+ }
+
for(FieldFormatting::type_list_values::const_iterator iter = list_values.begin(); iter != list_values.end(); ++iter)
{
- Gtk::TreeModel::iterator iterTree = m_refModel->append();
+ Gtk::TreeModel::iterator iterTree = list_store->append();
Gtk::TreeModel::Row row = *iterTree;
sharedptr<const LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
@@ -178,5 +192,10 @@ void ComboChoicesWithTreeModel::set_choices(const FieldFormatting::type_list_val
}
}
+Glib::RefPtr<Gtk::TreeModel> ComboChoicesWithTreeModel::get_choices_model()
+{
+ return m_refModel;
+}
+
} //namespace DataWidetChildren
} //namespace Glom
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.h b/glom/mode_data/datawidget/combochoiceswithtreemodel.h
index e98a682..edbb38a 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.h
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.h
@@ -39,19 +39,22 @@ public:
virtual void set_choices(const FieldFormatting::type_list_values& list_values);
+ //Not named get_model(), to avoid clashing with ComboBox::get_model().
+ Glib::RefPtr<Gtk::TreeModel> get_choices_model();
+
protected:
void init();
virtual void create_model(guint columns_count);
virtual void set_choices_with_second(const type_list_values_with_second& list_values);
- Glib::RefPtr<Gtk::ListStore> m_refModel;
-
typedef Gtk::TreeModelColumn<Glib::ustring> type_model_column;
typedef std::vector< type_model_column* > type_vec_model_columns;
type_vec_model_columns m_vec_model_columns;
private:
+ Glib::RefPtr<Gtk::TreeModel> m_refModel;
+
void delete_model();
};
diff --git a/glom/mode_data/datawidget/comboentry.cc b/glom/mode_data/datawidget/comboentry.cc
index e9b942c..8cb793f 100644
--- a/glom/mode_data/datawidget/comboentry.cc
+++ b/glom/mode_data/datawidget/comboentry.cc
@@ -114,7 +114,7 @@ void ComboEntry::create_model(guint columns_count)
ComboChoicesWithTreeModel::create_model(columns_count);
//Show model in the view:
- set_model(m_refModel);
+ set_model(get_choices_model());
set_text_column(0);
for(guint i = 0; i < columns_count; ++i)
diff --git a/glom/mode_data/db_adddel/cellrenderer_dblist.cc b/glom/mode_data/db_adddel/cellrenderer_dblist.cc
index 4057e57..d2c790b 100644
--- a/glom/mode_data/db_adddel/cellrenderer_dblist.cc
+++ b/glom/mode_data/db_adddel/cellrenderer_dblist.cc
@@ -42,7 +42,7 @@ void CellRendererDbList::create_model(guint columns_count)
DataWidgetChildren::ComboChoicesWithTreeModel::create_model(columns_count);
//Show model in the view:
- property_model() = m_refModel;
+ property_model() = get_choices_model();
property_text_column() = 0; //This must be a text column, in m_refModel.
property_editable() = true; //It would be useless if we couldn't edit it.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]