[glom] Simplify code that just re-emits signals.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Simplify code that just re-emits signals.
- Date: Mon, 12 Mar 2012 15:02:24 +0000 (UTC)
commit d0056b3634c98d60482fbcd90393672d4fafe87a
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Mar 12 15:46:22 2012 +0100
Simplify code that just re-emits signals.
ChangeLog | 4 ++
glom/mode_data/box_data_list.cc | 8 +----
glom/mode_data/box_data_list.h | 1 -
glom/mode_data/flowtablewithfields.cc | 63 +++++++--------------------------
glom/mode_data/flowtablewithfields.h | 10 -----
glom/mode_data/notebook_data.cc | 8 +----
glom/mode_data/notebook_data.h | 1 -
glom/signal_reemitter.h | 17 +++++++++
8 files changed, 36 insertions(+), 76 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e6a6300..9515a63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2012-03-12 Murray Cumming <murrayc murrayc com>
+ Simplify code that just re-emits signals.
+
+2012-03-12 Murray Cumming <murrayc murrayc com>
+
Reduce use of the derived ComboBoxText.
2012-03-12 Murray Cumming <murrayc murrayc com>
diff --git a/glom/mode_data/box_data_list.cc b/glom/mode_data/box_data_list.cc
index a9b0f1e..5dc6473 100644
--- a/glom/mode_data/box_data_list.cc
+++ b/glom/mode_data/box_data_list.cc
@@ -47,8 +47,7 @@ Box_Data_List::Box_Data_List()
m_AddDel.signal_user_requested_edit().connect(sigc::mem_fun(*this, &Box_Data_List::on_adddel_user_requested_edit));
m_AddDel.signal_script_button_clicked().connect(sigc::mem_fun(*this, &Box_Data_List::on_adddel_script_button_clicked));
m_AddDel.signal_sort_clause_changed().connect(sigc::mem_fun(*this, &Box_Data_List::on_adddel_user_sort_clause_changed));
- m_AddDel.signal_record_selection_changed().connect(
- sigc::mem_fun(*this, &Box_Data_List::on_adddel_record_selection_changed));
+ m_AddDel.signal_record_selection_changed().connect(m_signal_record_selection_changed.make_slot());
//TODO: Re-add this signal if this is really wanted, but make it part of a complete drag-and-drop feature for list views:
//m_AddDel.signal_user_reordered_columns().connect(sigc::mem_fun(*this, &Box_Data_List::on_adddel_user_reordered_columns));
@@ -543,11 +542,6 @@ void Box_Data_List::on_adddel_user_sort_clause_changed()
document->set_criteria_current(m_table_name, m_found_set);
}
-void Box_Data_List::on_adddel_record_selection_changed()
-{
- m_signal_record_selection_changed.emit();
-}
-
Gtk::TreeModel::iterator Box_Data_List::get_row_selected()
{
return m_AddDel.get_item_selected();
diff --git a/glom/mode_data/box_data_list.h b/glom/mode_data/box_data_list.h
index d807052..ac4e990 100644
--- a/glom/mode_data/box_data_list.h
+++ b/glom/mode_data/box_data_list.h
@@ -93,7 +93,6 @@ protected:
void on_adddel_user_requested_delete(const Gtk::TreeModel::iterator& rowStart, const Gtk::TreeModel::iterator& rowEnd);
void on_adddel_user_reordered_columns();
void on_adddel_user_sort_clause_changed();
- void on_adddel_record_selection_changed();
#ifndef GLOM_ENABLE_CLIENT_ONLY
void on_adddel_user_requested_layout();
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 359f4e7..e2aeac9 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -235,12 +235,12 @@ void FlowTableWithFields::add_layout_group(const sharedptr<LayoutGroup>& group,
add_layoutwidgetbase(flow_table);
//Connect signals:
- //TODO: Find a less repetitive way to do this chaining-up of signal emissions:
- flow_table->signal_field_edited().connect( sigc::mem_fun(*this, &FlowTableWithFields::on_flowtable_entry_edited) );
- flow_table->signal_field_choices_changed().connect( sigc::mem_fun(*this, &FlowTableWithFields::on_flowtable_entry_choices_changed) );
- flow_table->signal_field_open_details_requested().connect( sigc::mem_fun(*this, &FlowTableWithFields::on_flowtable_entry_open_details_requested) );
- flow_table->signal_related_record_changed().connect( sigc::mem_fun(*this, &FlowTableWithFields::on_flowtable_related_record_changed) );
- flow_table->signal_requested_related_details().connect( sigc::mem_fun(*this, &FlowTableWithFields::on_flowtable_requested_related_details) );
+ signal_connect_for_reemit_2args(flow_table->signal_field_edited(), m_signal_field_edited);
+ signal_connect_for_reemit_1arg(flow_table->signal_field_choices_changed(), m_signal_field_choices_changed);
+ signal_connect_for_reemit_2args(flow_table->signal_field_open_details_requested(), m_signal_field_open_details_requested);
+ signal_connect_for_reemit_1arg(flow_table->signal_related_record_changed(), m_signal_related_record_changed);
+ signal_connect_for_reemit_2args(flow_table->signal_requested_related_details(), m_signal_requested_related_details);
+
flow_table->signal_script_button_clicked().connect( sigc::mem_fun(*this, &FlowTableWithFields::on_script_button_clicked) );
flow_table->align_child_group_labels();
@@ -430,10 +430,11 @@ void FlowTableWithFields::add_layout_notebook(const sharedptr<LayoutItem_Noteboo
add_layoutwidgetbase(flow_table);
//Connect signal:
- flow_table->signal_field_edited().connect( sigc::mem_fun(*this, &FlowTableWithFields::on_flowtable_entry_edited) );
- flow_table->signal_field_open_details_requested().connect( sigc::mem_fun(*this, &FlowTableWithFields::on_flowtable_entry_open_details_requested) );
- flow_table->signal_related_record_changed().connect( sigc::mem_fun(*this, &FlowTableWithFields::on_flowtable_related_record_changed) );
- flow_table->signal_requested_related_details().connect( sigc::mem_fun(*this, &FlowTableWithFields::on_flowtable_requested_related_details) );
+ signal_connect_for_reemit_2args(flow_table->signal_field_edited(), m_signal_field_edited);
+ signal_connect_for_reemit_2args(flow_table->signal_field_open_details_requested(), m_signal_field_open_details_requested);
+ signal_connect_for_reemit_1arg(flow_table->signal_related_record_changed(), signal_related_record_changed());
+ signal_connect_for_reemit_2args(flow_table->signal_requested_related_details(), signal_requested_related_details());
+
flow_table->signal_script_button_clicked().connect( sigc::mem_fun(*this, &FlowTableWithFields::on_script_button_clicked) );
}
@@ -547,6 +548,7 @@ void FlowTableWithFields::add_field(const sharedptr<LayoutItem_Field>& layoutite
add(*eventbox, *(info.m_second), true);
info.m_second->signal_edited().connect( sigc::bind(sigc::mem_fun(*this, &FlowTableWithFields::on_entry_edited), layoutitem_field) ); //TODO: Is it a good idea to bind the LayoutItem? sigc::bind() probably stores a copy at this point.
+
info.m_second->signal_choices_changed().connect( sigc::bind(sigc::mem_fun(*this, &FlowTableWithFields::on_entry_choices_changed), layoutitem_field) );
#ifndef GLOM_ENABLE_CLIENT_ONLY
@@ -1095,21 +1097,6 @@ void FlowTableWithFields::on_entry_open_details_requested(const Gnome::Gda::Valu
m_signal_field_open_details_requested.emit(field, value);
}
-void FlowTableWithFields::on_flowtable_entry_edited(const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value)
-{
- m_signal_field_edited.emit(field, value);
-}
-
-void FlowTableWithFields::on_flowtable_entry_choices_changed(const sharedptr<const LayoutItem_Field>& field)
-{
- m_signal_field_choices_changed.emit(field);
-}
-
-void FlowTableWithFields::on_flowtable_entry_open_details_requested(const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value)
-{
- m_signal_field_open_details_requested.emit(field, value);
-}
-
void FlowTableWithFields::set_design_mode(bool value)
{
#ifndef GLOM_ENABLE_CLIENT_ONLY
@@ -1133,20 +1120,11 @@ void FlowTableWithFields::add_layoutwidgetbase(LayoutWidgetBase* layout_widget)
//Handle layout_changed signal:
#ifndef GLOM_ENABLE_CLIENT_ONLY
- layout_widget->signal_layout_changed().connect(sigc::mem_fun(*this, &FlowTableWithFields::on_layoutwidget_changed));
+ layout_widget->signal_layout_changed().connect(signal_layout_changed().make_slot());
#endif // !GLOM_ENABLE_CLIENT_ONLY
}
#ifndef GLOM_ENABLE_CLIENT_ONLY
-void FlowTableWithFields::on_layoutwidget_changed()
-{
- //Forward the signal to the container,
- //so it can make sure that the change is saved in the document.
- signal_layout_changed().emit();
-}
-#endif // !GLOM_ENABLE_CLIENT_ONLY
-
-#ifndef GLOM_ENABLE_CLIENT_ONLY
void FlowTableWithFields::on_datawidget_layout_item_added(LayoutWidgetBase::enumType item_type, DataWidget* pDataWidget)
{
//pDataWidget is the widget that asked us to add an item,
@@ -1237,14 +1215,6 @@ void FlowTableWithFields::on_datawidget_layout_item_added(LayoutWidgetBase::enum
}
#endif // !GLOM_ENABLE_CLIENT_ONLY
-void FlowTableWithFields::on_flowtable_related_record_changed(const Glib::ustring& relationship_name)
-{
- //TODO_DoublyRelated
-
- //Forward it to the parent:
- signal_related_record_changed().emit(relationship_name);
-}
-
//TODO: Use Value by const &
void FlowTableWithFields::on_portal_user_requested_details(Gnome::Gda::Value primary_key_value, Box_Data_Portal* portal_box)
{
@@ -1262,13 +1232,6 @@ void FlowTableWithFields::on_portal_user_requested_details(Gnome::Gda::Value pri
signal_requested_related_details().emit(table_name, primary_key);
}
-
-void FlowTableWithFields::on_flowtable_requested_related_details(const Glib::ustring& table_name, Gnome::Gda::Value primary_key_value)
-{
- //Forward it to the parent:
- signal_requested_related_details().emit(table_name, primary_key_value);
-}
-
void FlowTableWithFields::apply_size_groups_to_labels(const type_vec_sizegroups& size_groups)
{
//Remove widgets from any existing size group:
diff --git a/glom/mode_data/flowtablewithfields.h b/glom/mode_data/flowtablewithfields.h
index 5fba929..eef0ce2 100644
--- a/glom/mode_data/flowtablewithfields.h
+++ b/glom/mode_data/flowtablewithfields.h
@@ -212,20 +212,10 @@ private:
void on_entry_edited(const Gnome::Gda::Value& value, const sharedptr<const LayoutItem_Field> field);
void on_entry_choices_changed(const sharedptr<const LayoutItem_Field> field);
void on_entry_open_details_requested(const Gnome::Gda::Value& value, const sharedptr<const LayoutItem_Field> field);
- void on_flowtable_entry_edited(const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value);
- void on_flowtable_entry_choices_changed(const sharedptr<const LayoutItem_Field>& field);
- void on_flowtable_entry_open_details_requested(const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value);
- void on_flowtable_related_record_changed(const Glib::ustring& relationship_name);
- void on_flowtable_requested_related_details(const Glib::ustring& table_name, Gnome::Gda::Value primary_key_value);
void on_script_button_clicked(const sharedptr<LayoutItem_Button>& layout_item);
#ifndef GLOM_ENABLE_CLIENT_ONLY
- /// Remember the layout widget so we can iterate through them later.
- void on_layoutwidget_changed();
-#endif // !GLOM_ENABLE_CLIENT_ONLY
-
-#ifndef GLOM_ENABLE_CLIENT_ONLY
void on_datawidget_layout_item_added(LayoutWidgetBase::enumType item_type, DataWidget* pDataWidget);
#endif // !GLOM_ENABLE_CLIENT_ONLY
diff --git a/glom/mode_data/notebook_data.cc b/glom/mode_data/notebook_data.cc
index ceb49e6..b29a595 100644
--- a/glom/mode_data/notebook_data.cc
+++ b/glom/mode_data/notebook_data.cc
@@ -80,8 +80,7 @@ Notebook_Data::Notebook_Data()
&Notebook_Data::on_list_user_requested_details));
//Allow the parent widget to detect list selection changes:
- m_Box_List.signal_record_selection_changed().connect(sigc::mem_fun(*this,
- &Notebook_Data::on_list_selection_changed));
+ m_Box_List.signal_record_selection_changed().connect(m_signal_record_selection_changed.make_slot());
//Allow Details to ask List to ask Details to show a different record:
m_Box_Details.signal_nav_first().connect(sigc::mem_fun(m_Box_List, &Box_Data_List::on_details_nav_first));
@@ -251,11 +250,6 @@ void Notebook_Data::on_list_user_requested_details(const Gnome::Gda::Value& prim
primary_key_value));
}
-void Notebook_Data::on_list_selection_changed()
-{
- m_signal_record_selection_changed.emit();
-}
-
void Notebook_Data::on_details_user_requested_related_details(const Glib::ustring& table_name, Gnome::Gda::Value primary_key_value)
{
signal_record_details_requested().emit(table_name, primary_key_value);
diff --git a/glom/mode_data/notebook_data.h b/glom/mode_data/notebook_data.h
index 3763778..a9a6e61 100644
--- a/glom/mode_data/notebook_data.h
+++ b/glom/mode_data/notebook_data.h
@@ -99,7 +99,6 @@ protected:
private:
bool on_idle_show_details(const Gnome::Gda::Value& primary_key_value);
- void on_list_selection_changed();
protected:
//Member widgets:
diff --git a/glom/signal_reemitter.h b/glom/signal_reemitter.h
index 82b0fa3..79852c5 100644
--- a/glom/signal_reemitter.h
+++ b/glom/signal_reemitter.h
@@ -38,6 +38,12 @@ void reemit_1arg(T_arg1 arg1, const T_sig_to_emit& sig_to_emit)
sig_to_emit.emit(arg1);
}
+template<class T_sig_to_emit, typename T_arg1, typename T_arg2>
+void reemit_2args(T_arg1 arg1, T_arg2 arg2, const T_sig_to_emit& sig_to_emit)
+{
+ sig_to_emit.emit(arg1, arg2);
+}
+
//Note that sig_to_catch is by-value instead of const-reference,
//because connect() is a non-const method,
//and a non-const-reference could not be used with a temporary instance.
@@ -62,6 +68,17 @@ void signal_connect_for_reemit_1arg(sigc::signal1<void, T_arg1> sig_to_catch, co
sig_to_catch.connect( sigc::bind( sigc::ptr_fun(&reemit_1arg<T_sig_to_emit, T_arg1>), sig_to_emit) );
}
+/** Emit a signal when another signal is emitted.
+ * @param sig_to_catch The signal to handle.
+ * @param sig_to_emit The signal to emit when @a sig_to_catch is handled.
+ */
+template<class T_arg1, class T_arg2, class T_sig_to_emit>
+void signal_connect_for_reemit_2args(sigc::signal2<void, T_arg1, T_arg2> sig_to_catch, const T_sig_to_emit& sig_to_emit)
+{
+ sig_to_catch.connect( sigc::bind( sigc::ptr_fun(&reemit_2args<T_sig_to_emit, T_arg1, T_arg2>), sig_to_emit) );
+}
+
+
} //namespace Glom
#endif //GLOM_SIGNAL_REEMITTER_H
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]