[glom] Choices combo widgets: Improve the API.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Choices combo widgets: Improve the API.
- Date: Sat, 11 Sep 2010 11:44:20 +0000 (UTC)
commit 7f9c004e98d37bdde9bc0338fa04cd6d08a8cf02
Author: Murray Cumming <murrayc murrayc com>
Date: Sat Sep 11 13:43:54 2010 +0200
Choices combo widgets: Improve the API.
* glom/mode_data/datawidget/combochoiceswithtreemodel.[h|cc]:
Make create_model() non virtual, instead adding a pure virtual use_model().
* glom/mode_data/datawidget/combo.[h|cc]:
* glom/mode_data/datawidget/comboentry.[h|cc]:
* glom/mode_data/db_adddel/cellrenderer_dblist.[h|cc]: Change the
create_model() overrides to use_model() overrides.
ChangeLog | 11 +++++++++++
glom/mode_data/datawidget/combo.cc | 8 ++++----
glom/mode_data/datawidget/combo.h | 2 +-
.../datawidget/combochoiceswithtreemodel.cc | 3 +++
.../datawidget/combochoiceswithtreemodel.h | 7 ++++++-
glom/mode_data/datawidget/comboentry.cc | 9 ++++-----
glom/mode_data/datawidget/comboentry.h | 2 +-
glom/mode_data/db_adddel/cellrenderer_dblist.cc | 7 +++----
glom/mode_data/db_adddel/cellrenderer_dblist.h | 2 +-
9 files changed, 34 insertions(+), 17 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 98d1f0e..b206a94 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2010-09-11 Murray Cumming <murrayc murrayc com>
+ Choices combo widgets: Improve the API.
+
+ * glom/mode_data/datawidget/combochoiceswithtreemodel.[h|cc]:
+ Make create_model() non virtual, instead adding a pure virtual use_model().
+ * glom/mode_data/datawidget/combo.[h|cc]:
+ * glom/mode_data/datawidget/comboentry.[h|cc]:
+ * glom/mode_data/db_adddel/cellrenderer_dblist.[h|cc]: Change the
+ create_model() overrides to use_model() overrides.
+
+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
diff --git a/glom/mode_data/datawidget/combo.cc b/glom/mode_data/datawidget/combo.cc
index 7e5de3a..c19f110 100644
--- a/glom/mode_data/datawidget/combo.cc
+++ b/glom/mode_data/datawidget/combo.cc
@@ -69,16 +69,16 @@ ComboGlom::~ComboGlom()
{
}
-void ComboGlom::create_model(guint columns_count)
+void ComboGlom::use_model()
{
- //Create the model itself:
- ComboChoicesWithTreeModel::create_model(columns_count);
+ Glib::RefPtr<Gtk::TreeModel> model = get_choices_model();
//Show the model in the view:
- set_model(get_choices_model());
+ set_model(model);
clear();
+ const guint columns_count = model->get_n_columns();
for(guint i = 0; i < columns_count; ++i)
{
Gtk::CellRendererText* cell = Gtk::manage(new Gtk::CellRendererText);
diff --git a/glom/mode_data/datawidget/combo.h b/glom/mode_data/datawidget/combo.h
index 17afac0..f6cb62d 100644
--- a/glom/mode_data/datawidget/combo.h
+++ b/glom/mode_data/datawidget/combo.h
@@ -74,7 +74,7 @@ public:
private:
void init();
- virtual void create_model(guint columns_count);
+ virtual void use_model();
#ifndef GLOM_ENABLE_MAEMO
// Note that this is a normal signal handler when glibmm was complied
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
index b48a556..4aba921 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
@@ -69,6 +69,9 @@ void ComboChoicesWithTreeModel::create_model(guint columns_count)
//Create the model:
m_refModel = Gtk::ListStore::create(record);
+
+ //Call the derived class's (virtual) implementation of this:
+ use_model();
}
void ComboChoicesWithTreeModel::delete_model()
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.h b/glom/mode_data/datawidget/combochoiceswithtreemodel.h
index edbb38a..219893e 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.h
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.h
@@ -44,7 +44,12 @@ public:
protected:
void init();
- virtual void create_model(guint columns_count);
+ void create_model(guint columns_count);
+
+ /** Derived classes should implement this to present the model in their view,
+ * for instance by adding Gtk::CellRenderers.
+ */
+ virtual void use_model() = 0;
virtual void set_choices_with_second(const type_list_values_with_second& list_values);
diff --git a/glom/mode_data/datawidget/comboentry.cc b/glom/mode_data/datawidget/comboentry.cc
index 8cb793f..fc68d07 100644
--- a/glom/mode_data/datawidget/comboentry.cc
+++ b/glom/mode_data/datawidget/comboentry.cc
@@ -108,15 +108,14 @@ ComboEntry::~ComboEntry()
{
}
-void ComboEntry::create_model(guint columns_count)
+void ComboEntry::use_model()
{
- //Create the model itself:
- ComboChoicesWithTreeModel::create_model(columns_count);
-
//Show model in the view:
- set_model(get_choices_model());
+ Glib::RefPtr<Gtk::TreeModel> model = get_choices_model();
+ set_model(model);
set_text_column(0);
+ const guint columns_count = model->get_n_columns();
for(guint i = 0; i < columns_count; ++i)
{
Gtk::CellRendererText* cell = 0;
diff --git a/glom/mode_data/datawidget/comboentry.h b/glom/mode_data/datawidget/comboentry.h
index df8fe21..b151c12 100644
--- a/glom/mode_data/datawidget/comboentry.h
+++ b/glom/mode_data/datawidget/comboentry.h
@@ -73,7 +73,7 @@ public:
private:
void init();
- virtual void create_model(guint columns_count);
+ virtual void use_model();
//Overrides of default signal handlers:
diff --git a/glom/mode_data/db_adddel/cellrenderer_dblist.cc b/glom/mode_data/db_adddel/cellrenderer_dblist.cc
index d2c790b..7e6a64a 100644
--- a/glom/mode_data/db_adddel/cellrenderer_dblist.cc
+++ b/glom/mode_data/db_adddel/cellrenderer_dblist.cc
@@ -36,13 +36,12 @@ CellRendererDbList::~CellRendererDbList()
}
-void CellRendererDbList::create_model(guint columns_count)
+void CellRendererDbList::use_model()
{
- //Create the model itself:
- DataWidgetChildren::ComboChoicesWithTreeModel::create_model(columns_count);
+ Glib::RefPtr<Gtk::TreeModel> model = get_choices_model();
//Show model in the view:
- property_model() = get_choices_model();
+ property_model() = 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.
diff --git a/glom/mode_data/db_adddel/cellrenderer_dblist.h b/glom/mode_data/db_adddel/cellrenderer_dblist.h
index 6828f19..f48c0cb 100644
--- a/glom/mode_data/db_adddel/cellrenderer_dblist.h
+++ b/glom/mode_data/db_adddel/cellrenderer_dblist.h
@@ -47,7 +47,7 @@ public:
private:
- virtual void create_model(guint columns_count);
+ virtual void use_model();
virtual void on_editing_started(Gtk::CellEditable* cell_editable, const Glib::ustring& path);
virtual void set_value(const Gnome::Gda::Value& value);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]