[glom] Move code into a create_cell() utility function.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Move code into a create_cell() utility function.
- Date: Thu, 23 Sep 2010 08:27:41 +0000 (UTC)
commit a4e7233e75fb65e8bb9d06ce29769d37aeed9b18
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Sep 23 10:27:03 2010 +0200
Move code into a create_cell() utility function.
* glom/mode_data/db_adddel/cellrenderer*.[h|cc]: Move to
* glom/mode_data/datawidget/.
* glom/mode_data/db_adddel/db_adddel.[h|cc]:
construct_specified_columns_cellrenderer(): Move some code into:
* glom/mode_data/datawidget/cellcreation.[h|cc]: Added create_cell().
This is less efficient, because we repeat some dynamic casts, but it
makes construct_specified_columns_cellrenderer() less awfully huge by
separating the code that supports cell editing. And it makes the code
available to ComboChoices widgets later.
ChangeLog | 14 ++
Makefile_glom.am | 14 +-
.../cellrenderer_buttonimage.cc | 0
.../cellrenderer_buttonimage.h | 0
.../cellrenderer_buttontext.cc | 0
.../cellrenderer_buttontext.h | 0
.../cellrenderer_dblist.cc | 0
.../cellrenderer_dblist.h | 0
glom/mode_data/datawidget/combochoices.h | 3 +-
glom/mode_data/db_adddel/db_adddel.cc | 204 ++-----------------
10 files changed, 46 insertions(+), 189 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 208630f..b8cb056 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2010-09-23 Murray Cumming <murrayc murrayc com>
+
+ Move code into a create_cell() utility function.
+
+ * glom/mode_data/db_adddel/cellrenderer*.[h|cc]: Move to
+ * glom/mode_data/datawidget/.
+ * glom/mode_data/db_adddel/db_adddel.[h|cc]:
+ construct_specified_columns_cellrenderer(): Move some code into:
+ * glom/mode_data/datawidget/cellcreation.[h|cc]: Added create_cell().
+ This is less efficient, because we repeat some dynamic casts, but it
+ makes construct_specified_columns_cellrenderer() less awfully huge by
+ separating the code that supports cell editing. And it makes the code
+ available to ComboChoices widgets later.
+
2010-09-22 Murray Cumming <murrayc murrayc com>
Fix the build with latest unstable gtkmm 3.
diff --git a/Makefile_glom.am b/Makefile_glom.am
index 8b3890c..197d3cd 100644
--- a/Makefile_glom.am
+++ b/Makefile_glom.am
@@ -95,16 +95,10 @@ glom_source_files = \
glom/mode_data/box_data_portal.h \
glom/mode_data/buttonglom.cc \
glom/mode_data/buttonglom.h \
- glom/mode_data/db_adddel/cellrenderer_buttonimage.cc \
- glom/mode_data/db_adddel/cellrenderer_buttonimage.h \
- glom/mode_data/db_adddel/cellrenderer_buttontext.cc \
- glom/mode_data/db_adddel/cellrenderer_buttontext.h \
glom/mode_data/db_adddel/db_adddel.cc \
glom/mode_data/db_adddel/db_adddel.h \
glom/mode_data/db_adddel/db_adddel_withbuttons.cc \
glom/mode_data/db_adddel/db_adddel_withbuttons.h \
- glom/mode_data/db_adddel/cellrenderer_dblist.cc \
- glom/mode_data/db_adddel/cellrenderer_dblist.h \
glom/mode_data/db_adddel/db_treeviewcolumn_glom.cc \
glom/mode_data/db_adddel/db_treeviewcolumn_glom.h \
glom/mode_data/db_adddel/treemodel_db.cc \
@@ -117,6 +111,14 @@ glom_source_files = \
glom/mode_data/placeholder-glom.h \
glom/mode_data/datawidget/datawidget.cc \
glom/mode_data/datawidget/datawidget.h \
+ glom/mode_data/datawidget/cellcreation.cc \
+ glom/mode_data/datawidget/cellcreation.h \
+ glom/mode_data/datawidget/cellrenderer_buttonimage.cc \
+ glom/mode_data/datawidget/cellrenderer_buttonimage.h \
+ glom/mode_data/datawidget/cellrenderer_buttontext.cc \
+ glom/mode_data/datawidget/cellrenderer_buttontext.h \
+ glom/mode_data/datawidget/cellrenderer_dblist.cc \
+ glom/mode_data/datawidget/cellrenderer_dblist.h \
glom/mode_data/datawidget/checkbutton.cc \
glom/mode_data/datawidget/checkbutton.h \
glom/mode_data/datawidget/entry.cc \
diff --git a/glom/mode_data/db_adddel/cellrenderer_buttonimage.cc b/glom/mode_data/datawidget/cellrenderer_buttonimage.cc
similarity index 100%
rename from glom/mode_data/db_adddel/cellrenderer_buttonimage.cc
rename to glom/mode_data/datawidget/cellrenderer_buttonimage.cc
diff --git a/glom/mode_data/db_adddel/cellrenderer_buttonimage.h b/glom/mode_data/datawidget/cellrenderer_buttonimage.h
similarity index 100%
rename from glom/mode_data/db_adddel/cellrenderer_buttonimage.h
rename to glom/mode_data/datawidget/cellrenderer_buttonimage.h
diff --git a/glom/mode_data/db_adddel/cellrenderer_buttontext.cc b/glom/mode_data/datawidget/cellrenderer_buttontext.cc
similarity index 100%
rename from glom/mode_data/db_adddel/cellrenderer_buttontext.cc
rename to glom/mode_data/datawidget/cellrenderer_buttontext.cc
diff --git a/glom/mode_data/db_adddel/cellrenderer_buttontext.h b/glom/mode_data/datawidget/cellrenderer_buttontext.h
similarity index 100%
rename from glom/mode_data/db_adddel/cellrenderer_buttontext.h
rename to glom/mode_data/datawidget/cellrenderer_buttontext.h
diff --git a/glom/mode_data/db_adddel/cellrenderer_dblist.cc b/glom/mode_data/datawidget/cellrenderer_dblist.cc
similarity index 100%
rename from glom/mode_data/db_adddel/cellrenderer_dblist.cc
rename to glom/mode_data/datawidget/cellrenderer_dblist.cc
diff --git a/glom/mode_data/db_adddel/cellrenderer_dblist.h b/glom/mode_data/datawidget/cellrenderer_dblist.h
similarity index 100%
rename from glom/mode_data/db_adddel/cellrenderer_dblist.h
rename to glom/mode_data/datawidget/cellrenderer_dblist.h
diff --git a/glom/mode_data/datawidget/combochoices.h b/glom/mode_data/datawidget/combochoices.h
index 664776b..8fc68f9 100644
--- a/glom/mode_data/datawidget/combochoices.h
+++ b/glom/mode_data/datawidget/combochoices.h
@@ -51,13 +51,14 @@ public:
*/
virtual void set_choices_fixed(const FieldFormatting::type_list_values& list_values) = 0;
+ //This is not pure virtual, so some widgets can (temporarily) use a default inefficient implementation.
/** Show the list of related chocie values based on the LayoutItem's formatting choices.
* You should first call set_layout_item() to provide that formatting detail,
* so the widget knows what choices to show, and how to format them.
*
* See also refresh_data_from_database_with_foreign_key().
*/
- void set_choices_related(const Document* document);
+ virtual void set_choices_related(const Document* document);
/** Update a choices widget's list of related choices if a relevant value in its parent table has changed.
*
diff --git a/glom/mode_data/db_adddel/db_adddel.cc b/glom/mode_data/db_adddel/db_adddel.cc
index 73bab8e..3e9da0b 100644
--- a/glom/mode_data/db_adddel/db_adddel.cc
+++ b/glom/mode_data/db_adddel/db_adddel.cc
@@ -22,15 +22,15 @@
#include <algorithm> //For std::find.
#include <glibmm/i18n.h>
#include <glom/utility_widgets/cellrendererlist.h>
-#include <glom/mode_data/db_adddel/cellrenderer_dblist.h>
+#include <glom/mode_data/datawidget/cellrenderer_buttonimage.h>
+#include <glom/mode_data/datawidget/cellrenderer_buttontext.h>
+#include <glom/mode_data/datawidget/cellrenderer_dblist.h>
#include "db_treeviewcolumn_glom.h"
#include <libglom/data_structure/glomconversions.h>
#include <glom/dialog_invalid_data.h>
#include <glom/application.h>
-#include <glom/utils_ui.h>
-#include "cellrenderer_buttonimage.h"
-#include "cellrenderer_buttontext.h"
#include <glom/utils_ui.h> //For Utils::image_scale_keeping_ratio().
+#include <glom/mode_data/datawidget/cellcreation.h>
#include <libglom/db_utils.h>
#include <iostream> //For debug output.
@@ -684,122 +684,21 @@ int DbAddDel::get_fixed_cell_height()
return m_fixed_cell_height;
}
+
Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const sharedptr<LayoutItem>& layout_item, int model_column_index, int data_model_column_index)
{
InnerIgnore innerIgnore(this); //see comments for InnerIgnore class
- Gtk::CellRenderer* pCellRenderer = 0;
-
- //Create the appropriate cellrenderer type:
- sharedptr<LayoutItem_Field> item_field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
- if(item_field)
- {
- if(item_field->get_hidden())
- return 0;
+ Gtk::CellRenderer* pCellRenderer = create_cell(layout_item, m_table_name, get_document(), get_fixed_cell_height());
- switch(item_field->get_glom_type())
- {
- case(Field::TYPE_BOOLEAN):
- {
- pCellRenderer = Gtk::manage( new Gtk::CellRendererToggle() );
+ sharedptr<const LayoutItem_Field> item_field = sharedptr<const LayoutItem_Field>::cast_dynamic(layout_item);
- break;
- }
- case(Field::TYPE_IMAGE):
- {
- pCellRenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
-
- break;
- }
- default:
- {
- if(item_field->get_formatting_used().get_has_choices())
- {
- CellRendererDbList* rendererList = Gtk::manage( new CellRendererDbList() );
- rendererList->set_layout_item(item_field, m_table_name);
- bool as_radio_buttons = false; //Can't really be done in a list, so we ignore it.
- rendererList->set_restrict_values_to_list(
- item_field->get_formatting_used().get_choices_restricted(as_radio_buttons));
-
- pCellRenderer = rendererList;
- }
- else
- pCellRenderer = Gtk::manage( new Gtk::CellRendererText() );
+ //Set extra cellrenderer attributes, depending on the type used,
+ //to support editing:
- break;
- }
- } //switch
- }
- else
- {
- //Non-fields:
-
- sharedptr<LayoutItem_Image> item_image = sharedptr<LayoutItem_Image>::cast_dynamic(layout_item);
- if(item_image)
- {
- Gtk::CellRendererPixbuf* pixbuf_renderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
-
- Glib::RefPtr<Gdk::Pixbuf> pixbuf = Utils::get_pixbuf_for_gda_value(item_image->m_image);
- if(pixbuf)
- pixbuf_renderer->set_property("pixbuf", pixbuf);
- else
- pixbuf_renderer->set_property("stock-id", Gtk::StockID(Gtk::Stock::MISSING_IMAGE));
-
- pCellRenderer = pixbuf_renderer;
- }
- else
- {
- sharedptr<LayoutItem_Text> item_text = sharedptr<LayoutItem_Text>::cast_dynamic(layout_item);
- if(item_text)
- {
- Gtk::CellRendererText* pCellText = Gtk::manage( new Gtk::CellRendererText() );
- pCellText->set_property("text", item_text->get_text());
-
- pCellRenderer = pCellText;
- }
- else
- {
- sharedptr<LayoutItem_Button> item_button = sharedptr<LayoutItem_Button>::cast_dynamic(layout_item);
- if(item_button)
- {
- GlomCellRenderer_ButtonText* pCellButton = Gtk::manage( new GlomCellRenderer_ButtonText() );
- pCellButton->set_property("text", item_button->get_title_or_name());
- //pCellButton->set_fixed_width(50); //Otherwise it doesn't show up. TODO: Discover the width of the contents.
-
- #ifndef GLOM_ENABLE_MAEMO
- pCellButton->signal_clicked().connect(
- sigc::bind( sigc::mem_fun(*this, &DbAddDel::on_cell_layout_button_clicked), model_column_index) );
- #endif //GLOM_ENABLE_MAEMO
-
- pCellRenderer = pCellButton;
- }
- }
- }
- }
-
- //Use formatting:
- sharedptr<LayoutItem_WithFormatting> item_withformatting = sharedptr<LayoutItem_WithFormatting>::cast_dynamic(layout_item);
- if(item_withformatting && pCellRenderer)
- {
- apply_formatting(pCellRenderer, item_withformatting);
- }
-
- //Set extra cellrenderer attributes, depending on the type used:
Gtk::CellRendererText* pCellRendererText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
if(pCellRendererText)
{
- //Use an ellipze to indicate excessive text,
- //so that similar values do not look equal,
- //and to avoid multi-line comments. TODO: Is there a better way to restrict the height? This doesn't actually truncate multilines anyway.
- g_object_set(pCellRendererText->gobj(), "ellipsize", PANGO_ELLIPSIZE_END, (gpointer)0);
-
- //Restrict the height, to prevent multiline text cells,
- //and to allow TreeView performance optimisation:
- //TODO: Avoid specifying a width for the last column?
- int suitable_width = 0;
- pCellRendererText->get_property("width", suitable_width);
- pCellRendererText->set_fixed_size(suitable_width, get_fixed_cell_height() );
-
#ifndef GLOM_ENABLE_MAEMO //List views are non-editable on Maemo.
//Connect to edited signal:
if(item_field) //Only fields can be edited:
@@ -812,49 +711,6 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
sigc::bind( sigc::mem_fun(*this, &DbAddDel::on_treeview_cell_edited), model_column_index, data_model_column_index) );
}
#endif //GLOM_ENABLE_MAEMO
-
- //Choices:
- CellRendererList* pCellRendererList = dynamic_cast<CellRendererList*>(pCellRenderer);
- CellRendererDbList* pCellRendererDbList = dynamic_cast<CellRendererDbList*>(pCellRenderer);
- if(pCellRendererList) //Used for custom choices:
- {
- pCellRendererList->remove_all_list_items();
-
- if(item_field && item_field->get_formatting_used().get_has_custom_choices())
- {
- //set_choices_fixed() needs this, for the numeric layout:
- //pCellRendererCombo->set_layout_item(get_layout_item()->clone(), table_name); //TODO_Performance: We only need this for the numerical format.
- const FieldFormatting::type_list_values list_values = item_field->get_formatting_used().get_choices_custom();
- for(FieldFormatting::type_list_values::const_iterator iter = list_values.begin(); iter != list_values.end(); ++iter)
- {
- pCellRendererList->append_list_item( Conversions::get_text_for_gda_value(item_field->get_glom_type(), *iter, item_field->get_formatting_used().m_numeric_format) );
- }
- }
- }
- else if(pCellRendererDbList) //Used for related choices:
- {
- if(item_field && item_field->get_formatting_used().get_has_related_choices())
- {
- sharedptr<const Relationship> choice_relationship;
- sharedptr<const LayoutItem_Field> choice_field;
- sharedptr<const LayoutGroup> choice_extras;
- bool choice_show_all;
- item_field->get_formatting_used().get_choices_related(choice_relationship, choice_field, choice_extras, choice_show_all);
-
- if(choice_relationship && choice_field)
- {
- const Glib::ustring to_table = choice_relationship->get_to_table();
-
- //TODO: Update this when the relationship's field value changes:
- if(choice_show_all) //Otherwise it must change whenever the relationships's ID value changes.
- {
- const Utils::type_list_values_with_second list_values =
- Utils::get_choice_values_all(get_document(), item_field);
- pCellRendererDbList->set_choices_with_second(list_values);
- }
- }
- }
- }
}
else
{
@@ -882,36 +738,20 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
}
}
- return pCellRenderer;
-}
-
-void DbAddDel::apply_formatting(Gtk::CellRenderer* renderer, const sharedptr<const LayoutItem_WithFormatting>& layout_item)
-{
- Gtk::CellRendererText* text_renderer = dynamic_cast<Gtk::CellRendererText*>(renderer);
- if(!text_renderer)
- return;
-
- //Use the text formatting:
-
- //Horizontal alignment:
- const FieldFormatting::HorizontalAlignment alignment =
- layout_item->get_formatting_used_horizontal_alignment();
- const float x_align = (alignment == FieldFormatting::HORIZONTAL_ALIGNMENT_LEFT ? 0.0 : 1.0);
- text_renderer->property_xalign() = x_align;
-
- const FieldFormatting& formatting = layout_item->get_formatting_used();
-
- const Glib::ustring font_desc = formatting.get_text_format_font();
- if(!font_desc.empty())
- text_renderer->property_font() = font_desc;
-
- const Glib::ustring fg = formatting.get_text_format_color_foreground();
- if(!fg.empty())
- text_renderer->property_foreground() = fg;
+ GlomCellRenderer_ButtonText* pCellButton = Gtk::manage( new GlomCellRenderer_ButtonText() );
+ if(pCellButton)
+ {
+ sharedptr<const LayoutItem_Button> item_button = sharedptr<const LayoutItem_Button>::cast_dynamic(layout_item);
+ if(item_button)
+ {
+ #ifndef GLOM_ENABLE_MAEMO
+ pCellButton->signal_clicked().connect(
+ sigc::bind( sigc::mem_fun(*this, &DbAddDel::on_cell_layout_button_clicked), model_column_index) );
+ #endif //GLOM_ENABLE_MAEMO
+ }
+ }
- const Glib::ustring bg = formatting.get_text_format_color_background();
- if(!bg.empty())
- text_renderer->property_background() = bg;
+ return pCellRenderer;
}
void DbAddDel::construct_specified_columns()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]