glom r1542 - in trunk: . glom/libglom/data_structure/layout glom/libglom/document glom/mode_data
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: glom r1542 - in trunk: . glom/libglom/data_structure/layout glom/libglom/document glom/mode_data
- Date: Wed, 9 Apr 2008 15:50:42 +0100 (BST)
Author: murrayc
Date: Wed Apr 9 15:50:42 2008
New Revision: 1542
URL: http://svn.gnome.org/viewvc/glom?rev=1542&view=rev
Log:
2008-04-09 Murray Cumming <murrayc murrayc com>
* glom/libglom/data_structure/layout/layoutgroup.cc
* glom/libglom/data_structure/layout/layoutgroup.h:
Added has_any_fields().
* glom/libglom/document/document_glom.cc
* glom/libglom/document/document_glom.h
Added get_data_layout_groups_have_any_fields().
* glom/mode_data/box_data_details.cc on_button_new():
* glom/mode_data/box_data_list.cc on_adddel_user_requested_add():
Warn the user if the layout has no dialogs, and do not try to add a
record, because there would be nothing to see an no way to enter data.
Modified:
trunk/ChangeLog
trunk/glom/libglom/data_structure/layout/layoutgroup.cc
trunk/glom/libglom/data_structure/layout/layoutgroup.h
trunk/glom/libglom/document/document_glom.cc
trunk/glom/libglom/document/document_glom.h
trunk/glom/mode_data/box_data_details.cc
trunk/glom/mode_data/box_data_list.cc
Modified: trunk/glom/libglom/data_structure/layout/layoutgroup.cc
==============================================================================
--- trunk/glom/libglom/data_structure/layout/layoutgroup.cc (original)
+++ trunk/glom/libglom/data_structure/layout/layoutgroup.cc Wed Apr 9 15:50:42 2008
@@ -110,6 +110,31 @@
return false;
}
+bool LayoutGroup::has_any_fields() const
+{
+ for(type_list_items::const_iterator iter = m_list_items.begin(); iter != m_list_items.end(); ++iter)
+ {
+ sharedptr<LayoutItem> item = *iter;
+ sharedptr<LayoutItem_Field> field_item = sharedptr<LayoutItem_Field>::cast_dynamic(item);
+ if(field_item)
+ {
+ return true;
+ }
+ else
+ {
+ //Recurse into the child groups:
+ sharedptr<LayoutGroup> group_item = sharedptr<LayoutGroup>::cast_dynamic(item);
+ if(group_item)
+ {
+ if(group_item->has_any_fields())
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
void LayoutGroup::add_item(const sharedptr<LayoutItem>& item)
{
m_list_items.push_back(item);
Modified: trunk/glom/libglom/data_structure/layout/layoutgroup.h
==============================================================================
--- trunk/glom/libglom/data_structure/layout/layoutgroup.h (original)
+++ trunk/glom/libglom/data_structure/layout/layoutgroup.h Wed Apr 9 15:50:42 2008
@@ -40,8 +40,17 @@
virtual LayoutItem* clone() const;
+ /** Discover whether the layout group contains the specified field.
+ * @param field_name The name of the field to seach for.
+ * @result True if the field is in the layout group (or its child groups).
+ */
bool has_field(const Glib::ustring& field_name) const;
+ /** Discover whether the layout group contains any fields.
+ * @result True if the field is in the layout group (or its child groups).
+ */
+ bool has_any_fields() const;
+
/** Add the item to the end of the list.
* @param item The item to add.
*/
Modified: trunk/glom/libglom/document/document_glom.cc
==============================================================================
--- trunk/glom/libglom/document/document_glom.cc (original)
+++ trunk/glom/libglom/document/document_glom.cc Wed Apr 9 15:50:42 2008
@@ -1459,6 +1459,20 @@
return type_list_layout_groups(); //not found
}
+bool Document_Glom::get_data_layout_groups_have_any_fields(const Glib::ustring& layout_name, const Glib::ustring& parent_table_name) const
+{
+ //TODO_Performance: This could make the response to some button slow, such as the Add button, which does a check for this.
+ type_list_layout_groups layout_groups = get_data_layout_groups(layout_name, parent_table_name);
+ for(type_list_layout_groups::iterator iter = layout_groups.begin(); iter != layout_groups.end(); ++iter)
+ {
+ sharedptr<LayoutGroup> layout_group = *iter;
+ if(layout_group && layout_group->has_any_fields())
+ return true;
+ }
+
+ return false;
+}
+
void Document_Glom::set_data_layout_groups(const Glib::ustring& layout_name, const Glib::ustring& parent_table_name, const type_list_layout_groups& groups)
{
const Glib::ustring child_table_name = parent_table_name; //TODO: Remove this cruft.
Modified: trunk/glom/libglom/document/document_glom.h
==============================================================================
--- trunk/glom/libglom/document/document_glom.h (original)
+++ trunk/glom/libglom/document/document_glom.h Wed Apr 9 15:50:42 2008
@@ -186,8 +186,26 @@
typedef std::vector< sharedptr<LayoutGroup> > type_list_layout_groups;
+
+ /** Get the layout groups for a layout.
+ * @param layout_name The name of the layout, such as list or details.
+ * @param parent_table_name The name of the table for which this layout should appear.
+ * @result A list of layout groups at the top-level of the requested layout.
+ */
type_list_layout_groups get_data_layout_groups(const Glib::ustring& layout_name, const Glib::ustring& parent_table_name) const;
+ /** Discover whether there are any fields in the layout.
+ * @param layout_name The name of the layout, such as list or details.
+ * @param parent_table_name The name of the table for which this layout should appear.
+ * @result true if there is at least one field in the layout group or its sub groups.
+ */
+ bool get_data_layout_groups_have_any_fields(const Glib::ustring& layout_name, const Glib::ustring& parent_table_name) const;
+
+ /** Set the layout groups for a layout.
+ * @param layout_name The name of the layout, such as list or details.
+ * @param parent_table_name The name of the table for which this layout should appear.
+ * @param groups A list of layout groups at the top-level of the requested layout.
+ */
void set_data_layout_groups(const Glib::ustring& layout_name, const Glib::ustring& parent_table_name, const type_list_layout_groups& groups);
/**
@@ -294,24 +312,22 @@
// Used by Relationship Overview dialog to preserve table locations accross instantiations:
- /**
- * Retrieve the x and y coordinates for the given table position.
- *
- * @param table_name The name of the table to query.
- * @param x The x coordinate of the table position.
- * @param y The y coordinate of the table position.
- * @return false if the table does not have any
- */
- bool get_table_overview_position ( const Glib::ustring &table_name, float &x, float &y ) const;
+ /** Retrieve the x and y coordinates for the given table position.
+ *
+ * @param table_name The name of the table to query.
+ * @param x The x coordinate of the table position.
+ * @param y The y coordinate of the table position.
+ * @return false if the table does not have any
+ */
+ bool get_table_overview_position ( const Glib::ustring &table_name, float &x, float &y ) const;
- /**
- * Set the position of a table in the relationship overview dialog.
- *
- * @param table_name The name of the table to modify.
- * @param x The x coordinate of the table position.
- * @param y The y coordinate of the table position.
- */
- void set_table_overview_position ( const Glib::ustring &table_name, float x, float y );
+ /** Set the position of a table in the relationship overview dialog.
+ *
+ * @param table_name The name of the table to modify.
+ * @param x The x coordinate of the table position.
+ * @param y The y coordinate of the table position.
+ */
+ void set_table_overview_position ( const Glib::ustring &table_name, float x, float y );
enum userLevelReason
{
Modified: trunk/glom/mode_data/box_data_details.cc
==============================================================================
--- trunk/glom/mode_data/box_data_details.cc (original)
+++ trunk/glom/mode_data/box_data_details.cc Wed Apr 9 15:50:42 2008
@@ -370,24 +370,39 @@
void Box_Data_Details::on_button_new()
{
- if(confirm_discard_unstored_data())
- {
- if(m_field_primary_key && m_field_primary_key->get_auto_increment()) //If the primary key is an auto-increment:
- {
- //Just make a new record, and show it:
- Gnome::Gda::Value primary_key_value = generate_next_auto_increment(m_table_name, m_field_primary_key->get_name()); //TODO: This should return a Gda::Value
+ if(!confirm_discard_unstored_data())
+ return;
- record_new(false /* use entered field data */, primary_key_value);
- refresh_data_from_database_with_primary_key(primary_key_value);
- }
- else
- {
- //It's not an auto-increment primary key,
- //so just blank the fields ready for a primary key later.
- refresh_data_from_database_blank(); //shows blank record.
+ //Don't try to add a record to a list with no fields.
+ if(m_FieldsShown.empty())
+ {
+ //Warn the user that they won't see anything if there are no fields on the layout,
+ //doing an extra check:
+ Document_Glom* document = get_document();
+ if( document && !(document->get_data_layout_groups_have_any_fields(m_layout_name, m_table_name)) )
+ {
+ Gtk::Window* parent_window = get_app_window();
+ if(parent_window)
+ Utils::show_ok_dialog(_("Layout Contains No Fields"), _("There are no fields on the layout, so there is no way to enter data in a new record."), *parent_window, Gtk::MESSAGE_ERROR);
}
- } //if(confirm_discard_unstored_data())
+ return;
+ }
+
+ if(m_field_primary_key && m_field_primary_key->get_auto_increment()) //If the primary key is an auto-increment:
+ {
+ //Just make a new record, and show it:
+ Gnome::Gda::Value primary_key_value = generate_next_auto_increment(m_table_name, m_field_primary_key->get_name()); //TODO: This should return a Gda::Value
+
+ record_new(false /* use entered field data */, primary_key_value);
+ refresh_data_from_database_with_primary_key(primary_key_value);
+ }
+ else
+ {
+ //It's not an auto-increment primary key,
+ //so just blank the fields ready for a primary key later.
+ refresh_data_from_database_blank(); //shows blank record.
+ }
}
void Box_Data_Details::on_button_del()
Modified: trunk/glom/mode_data/box_data_list.cc
==============================================================================
--- trunk/glom/mode_data/box_data_list.cc (original)
+++ trunk/glom/mode_data/box_data_list.cc Wed Apr 9 15:50:42 2008
@@ -193,8 +193,23 @@
void Box_Data_List::on_adddel_user_requested_add()
{
- if(m_FieldsShown.empty())
- return; //Don't try to add a record to a list with no fields.
+ //Don't try to add a record to a list with no fields.
+
+ //This isn't enough as a quick check, because the primary key is always in this list: if(m_FieldsShown.empty())
+ //{
+ //Warn the user that they won't see anything if there are no fields on the layout,
+ //doing an extra check:
+ //TODO_performance: Maybe this slows down the response when clicking Add.
+ Document_Glom* document = get_document();
+ if( document && !(document->get_data_layout_groups_have_any_fields(m_layout_name, m_table_name)) )
+ {
+ Gtk::Window* parent_window = get_app_window();
+ if(parent_window)
+ Utils::show_ok_dialog(_("Layout Contains No Fields"), _("There are no fields on the layout, so there is no way to enter data in a new record."), *parent_window, Gtk::MESSAGE_ERROR);
+
+ return;
+ }
+ //}
Gtk::TreeModel::iterator iter = m_AddDel.get_item_placeholder();
if(iter)
@@ -578,11 +593,15 @@
//Don't go past the last record:
if( !m_AddDel.get_is_last_row(iter) )
{
+ std::cout << "DEBUG: Box_Data_List::on_details_nav_next(): The current row was not the last row." << std::endl;
+
iter++;
m_AddDel.select_item(iter);
signal_user_requested_details().emit(m_AddDel.get_value_key_selected());
}
+ else
+ std::cout << "DEBUG: Box_Data_List::on_details_nav_next(): Not going past the last row." << std::endl;
}
}
@@ -594,8 +613,9 @@
m_AddDel.select_item(iter);
signal_user_requested_details().emit(m_AddDel.get_value_key_selected());
}
- else
- signal_user_requested_details().emit(Gnome::Gda::Value()); //Show a blank record if there are no records.
+
+ //No, don't do this. When would that ever be a good idea? murrayc:
+ //signal_user_requested_details().emit(Gnome::Gda::Value()); //Show a blank record if there are no records.
}
void Box_Data_List::on_details_record_deleted(const Gnome::Gda::Value& primary_key_value)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]