[glom] Split Base_DB_Table_Data into a read-only base class.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Split Base_DB_Table_Data into a read-only base class.
- Date: Sat, 18 Sep 2010 10:58:11 +0000 (UTC)
commit d4e5e3e40bb8716da21f0d93be4c18ffa50546ac
Author: Murray Cumming <murrayc murrayc com>
Date: Sat Sep 18 12:28:25 2010 +0200
Split Base_DB_Table_Data into a read-only base class.
* glom/Makefile_glom.am:
* po/POTFILES.in:
* glom/base_db_table_data_readonly.[h|cc]: Created this new class from
parts of:
* glom/base_db_table_data.[h|cc]: which now derives from it.
This let us use it for classes that do not allow the user to change the data.
For instance, choice combo boxes.
ChangeLog | 12 +++
Makefile_glom.am | 2 +
glom/base_db_table_data.cc | 155 +++++++++++++++++------------------
glom/base_db_table_data.h | 28 ++-----
glom/base_db_table_data_readonly.cc | 50 +++++++++++
glom/base_db_table_data_readonly.h | 58 +++++++++++++
po/POTFILES.in | 1 +
7 files changed, 205 insertions(+), 101 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f7e6cac..eba07a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-09-18 Murray Cumming <murrayc murrayc com>
+
+ Split Base_DB_Table_Data into a read-only base class.
+
+ * glom/Makefile_glom.am:
+ * po/POTFILES.in:
+ * glom/base_db_table_data_readonly.[h|cc]: Created this new class from
+ parts of:
+ * glom/base_db_table_data.[h|cc]: which now derives from it.
+ This let us use it for classes that do not allow the user to change the data.
+ For instance, choice combo boxes.
+
2010-09-17 Murray Cumming <murrayc murrayc com>
Fix the build with gtkmm 3 from git master.
diff --git a/Makefile_glom.am b/Makefile_glom.am
index 6a35d31..8b3890c 100644
--- a/Makefile_glom.am
+++ b/Makefile_glom.am
@@ -24,6 +24,8 @@ glom_source_files = \
glom/base_db_table.h \
glom/base_db_table_data.cc \
glom/base_db_table_data.h \
+ glom/base_db_table_data_readonly.cc \
+ glom/base_db_table_data_readonly.h \
glom/box_db_table.cc \
glom/box_db_table.h \
glom/box_reports.cc \
diff --git a/glom/base_db_table_data.cc b/glom/base_db_table_data.cc
index f631840..33efffe 100644
--- a/glom/base_db_table_data.cc
+++ b/glom/base_db_table_data.cc
@@ -39,14 +39,6 @@ Base_DB_Table_Data::~Base_DB_Table_Data()
{
}
-bool Base_DB_Table_Data::refresh_data_from_database()
-{
- if(!ConnectionPool::get_instance()->get_ready_to_connect())
- return false;
-
- return fill_from_database();
-}
-
Gnome::Gda::Value Base_DB_Table_Data::get_entered_field_data_field_only(const sharedptr<const Field>& field) const
{
sharedptr<LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::create();
@@ -62,6 +54,7 @@ Gnome::Gda::Value Base_DB_Table_Data::get_entered_field_data(const sharedptr<con
return Gnome::Gda::Value(); //null
}
+
Gtk::TreeModel::iterator Base_DB_Table_Data::get_row_selected()
{
//This in meaningless for Details,
@@ -242,45 +235,6 @@ bool Base_DB_Table_Data::record_new(bool use_entered_data, const Gnome::Gda::Val
return false; //Failed.
}
-
-bool Base_DB_Table_Data::get_related_record_exists(const sharedptr<const Relationship>& relationship, const Gnome::Gda::Value& key_value)
-{
- BusyCursor cursor(Application::get_application());
-
- bool result = false;
-
- //Don't try doing a NULL=NULL or ""="" relationship:
- if(Glom::Conversions::value_is_empty(key_value))
- return false;
-
- //TODO_Performance: It's very possible that this is slow.
- //We don't care how many records there are, only whether there are more than zero.
- const Glib::ustring to_field = relationship->get_to_field();
- const Glib::ustring related_table = relationship->get_to_table();
-
- //TODO_Performance: Is this the best way to just find out whether there is one record that meets this criteria?
- Glib::RefPtr<Gnome::Gda::SqlBuilder> builder =
- Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
- builder->select_add_field(to_field, related_table);
- builder->select_add_target(related_table);
- builder->set_where(
- builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
- builder->add_field_id(to_field, related_table),
- builder->add_expr(key_value)));
-
- Glib::RefPtr<Gnome::Gda::DataModel> records = DbUtils::query_execute_select(builder);
- if(!records)
- handle_error();
- else
- {
- //Field contents:
- if(records->get_n_rows())
- result = true;
- }
-
- return result;
-}
-
bool Base_DB_Table_Data::add_related_record_for_field(const sharedptr<const LayoutItem_Field>& layout_item_parent,
const sharedptr<const Relationship>& relationship,
const sharedptr<const Field>& primary_key_field,
@@ -484,6 +438,79 @@ Base_DB_Table_Data::type_signal_record_changed Base_DB_Table_Data::signal_record
}
+bool Base_DB_Table_Data::get_related_record_exists(const sharedptr<const Relationship>& relationship, const Gnome::Gda::Value& key_value)
+{
+ BusyCursor cursor(Application::get_application());
+
+ bool result = false;
+
+ //Don't try doing a NULL=NULL or ""="" relationship:
+ if(Glom::Conversions::value_is_empty(key_value))
+ return false;
+
+ //TODO_Performance: It's very possible that this is slow.
+ //We don't care how many records there are, only whether there are more than zero.
+ const Glib::ustring to_field = relationship->get_to_field();
+ const Glib::ustring related_table = relationship->get_to_table();
+
+ //TODO_Performance: Is this the best way to just find out whether there is one record that meets this criteria?
+ Glib::RefPtr<Gnome::Gda::SqlBuilder> builder =
+ Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
+ builder->select_add_field(to_field, related_table);
+ builder->select_add_target(related_table);
+ builder->set_where(
+ builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
+ builder->add_field_id(to_field, related_table),
+ builder->add_expr(key_value)));
+
+ Glib::RefPtr<Gnome::Gda::DataModel> records = DbUtils::query_execute_select(builder);
+ if(!records)
+ handle_error();
+ else
+ {
+ //Field contents:
+ if(records->get_n_rows())
+ result = true;
+ }
+
+ return result;
+}
+
+
+/** Get the shown fields that are in related tables, via a relationship using @a field_name changes.
+ */
+Base_DB_Table_Data::type_vecLayoutFields Base_DB_Table_Data::get_related_fields(const sharedptr<const LayoutItem_Field>& field) const
+{
+ type_vecLayoutFields result;
+
+ const Document* document = dynamic_cast<const Document*>(get_document());
+ if(document)
+ {
+ const Glib::ustring field_name = field->get_name(); //At the moment, relationships can not be based on related fields on the from side.
+ for(type_vecLayoutFields::const_iterator iter = m_FieldsShown.begin(); iter != m_FieldsShown.end(); ++iter)
+ {
+ sharedptr<LayoutItem_Field> layout_field = *iter;
+ //Examine each field that looks up its data from a relationship:
+ if(layout_field->get_has_relationship_name())
+ {
+ //Get the relationship information:
+ sharedptr<const Relationship> relationship = document->get_relationship(m_table_name, layout_field->get_relationship_name());
+ if(relationship)
+ {
+ //If the relationship uses the specified field:
+ if(relationship->get_from_field() == field_name)
+ {
+ //Add it:
+ result.push_back(layout_field);
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+}
+
void Base_DB_Table_Data::refresh_related_fields(const LayoutFieldInRecord& field_in_record_changed, const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& /* field_value */)
{
//std::cout << "DEBUG: Base_DB_Table_Data::refresh_related_fields()" << std::endl;
@@ -545,38 +572,4 @@ void Base_DB_Table_Data::refresh_related_fields(const LayoutFieldInRecord& field
}
}
-/** Get the shown fields that are in related tables, via a relationship using @a field_name changes.
- */
-Base_DB_Table_Data::type_vecLayoutFields Base_DB_Table_Data::get_related_fields(const sharedptr<const LayoutItem_Field>& field) const
-{
- type_vecLayoutFields result;
-
- const Document* document = dynamic_cast<const Document*>(get_document());
- if(document)
- {
- const Glib::ustring field_name = field->get_name(); //At the moment, relationships can not be based on related fields on the from side.
- for(type_vecLayoutFields::const_iterator iter = m_FieldsShown.begin(); iter != m_FieldsShown.end(); ++iter)
- {
- sharedptr<LayoutItem_Field> layout_field = *iter;
- //Examine each field that looks up its data from a relationship:
- if(layout_field->get_has_relationship_name())
- {
- //Get the relationship information:
- sharedptr<const Relationship> relationship = document->get_relationship(m_table_name, layout_field->get_relationship_name());
- if(relationship)
- {
- //If the relationship uses the specified field:
- if(relationship->get_from_field() == field_name)
- {
- //Add it:
- result.push_back(layout_field);
- }
- }
- }
- }
- }
-
- return result;
-}
-
} //namespace Glom
diff --git a/glom/base_db_table_data.h b/glom/base_db_table_data.h
index ea4f5cd..b2d68e8 100644
--- a/glom/base_db_table_data.h
+++ b/glom/base_db_table_data.h
@@ -22,9 +22,7 @@
#ifndef BASE_DB_TABLE_DATA_H
#define BASE_DB_TABLE_DATA_H
-#include "base_db_table.h"
-#include <libglom/data_structure/field.h>
-#include <algorithm> //find_if used in various places.
+#include "base_db_table_data_readonly.h"
namespace Glom
{
@@ -32,13 +30,11 @@ namespace Glom
/** A base class some database functionality
* for use with a specific database table, showing data from the table.
*/
-class Base_DB_Table_Data : public Base_DB_Table
+class Base_DB_Table_Data : public Base_DB_Table_Data_ReadOnly
{
public:
Base_DB_Table_Data();
virtual ~Base_DB_Table_Data();
-
- virtual bool refresh_data_from_database();
/** Tell the parent widget that something has changed in one of the shown records,
* or a record was added or deleted.
@@ -58,18 +54,18 @@ protected:
Gnome::Gda::Value get_entered_field_data_field_only(const sharedptr<const Field>& field) const;
virtual Gnome::Gda::Value get_entered_field_data(const sharedptr<const LayoutItem_Field>& field) const;
-
- virtual sharedptr<Field> get_field_primary_key() const = 0;
- virtual Gnome::Gda::Value get_primary_key_value_selected() const = 0;
+
+ //Gets the row being edited, for derived classes that have rows.
+ virtual Gtk::TreeModel::iterator get_row_selected();
+
virtual void set_primary_key_value(const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& value) = 0;
- virtual Gnome::Gda::Value get_primary_key_value(const Gtk::TreeModel::iterator& row) const = 0;
virtual void refresh_related_fields(const LayoutFieldInRecord& field_in_record_changed, const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& field_value);
/** Get the fields that are in related tables, via a relationship using @a field_name changes.
*/
type_vecLayoutFields get_related_fields(const sharedptr<const LayoutItem_Field>& field) const;
-
+
/** Ask the user if he really wants to delete the record.
*/
bool confirm_delete_record();
@@ -84,16 +80,8 @@ protected:
virtual void on_record_added(const Gnome::Gda::Value& primary_key_value, const Gtk::TreeModel::iterator& row); //Overridden by derived classes.
virtual void on_record_deleted(const Gnome::Gda::Value& primary_key_value); //Overridden by derived classes.
- //Gets the row being edited, for derived classes that have rows.
- virtual Gtk::TreeModel::iterator get_row_selected();
-
- FoundSet m_found_set;
-
- type_vec_fields m_TableFields; //A cache, so we don't have to repeatedly get them from the Document.
- type_vecLayoutFields m_FieldsShown; //And any extra keys needed by shown fields.
-
type_signal_record_changed m_signal_record_changed;
-
+
private:
bool get_related_record_exists(const sharedptr<const Relationship>& relationship, const Gnome::Gda::Value& key_value);
};
diff --git a/glom/base_db_table_data_readonly.cc b/glom/base_db_table_data_readonly.cc
new file mode 100644
index 0000000..6259f99
--- /dev/null
+++ b/glom/base_db_table_data_readonly.cc
@@ -0,0 +1,50 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2004 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include "base_db_table_data.h"
+#include <libglom/data_structure/glomconversions.h>
+#include <glom/application.h>
+#include <glom/python_embed/glom_python.h>
+#include <glom/utils_ui.h>
+#include <libglom/db_utils.h>
+#include <sstream>
+#include <glibmm/i18n.h>
+
+namespace Glom
+{
+
+Base_DB_Table_Data_ReadOnly::Base_DB_Table_Data_ReadOnly()
+{
+}
+
+Base_DB_Table_Data_ReadOnly::~Base_DB_Table_Data_ReadOnly()
+{
+}
+
+bool Base_DB_Table_Data_ReadOnly::refresh_data_from_database()
+{
+ if(!ConnectionPool::get_instance()->get_ready_to_connect())
+ return false;
+
+ return fill_from_database();
+}
+
+} //namespace Glom
diff --git a/glom/base_db_table_data_readonly.h b/glom/base_db_table_data_readonly.h
new file mode 100644
index 0000000..0aff833
--- /dev/null
+++ b/glom/base_db_table_data_readonly.h
@@ -0,0 +1,58 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2004 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#ifndef BASE_DB_TABLE_DATA_READONLY_H
+#define BASE_DB_TABLE_DATA_READONLY_H
+
+#include "base_db_table.h"
+#include <libglom/data_structure/field.h>
+#include <algorithm> //find_if used in various places.
+
+namespace Glom
+{
+
+/** A base class some database functionality
+ * for use with a specific database table, showing data from the table.
+ */
+class Base_DB_Table_Data_ReadOnly : public Base_DB_Table
+{
+public:
+ Base_DB_Table_Data_ReadOnly();
+ virtual ~Base_DB_Table_Data_ReadOnly();
+
+ virtual bool refresh_data_from_database();
+
+protected:
+
+ //TODO: Move these to Base_DB_Table_Data too?
+ virtual sharedptr<Field> get_field_primary_key() const = 0;
+ virtual Gnome::Gda::Value get_primary_key_value_selected() const = 0;
+ virtual Gnome::Gda::Value get_primary_key_value(const Gtk::TreeModel::iterator& row) const = 0;
+
+ FoundSet m_found_set;
+
+ type_vec_fields m_TableFields; //A cache, so we don't have to repeatedly get them from the Document.
+ type_vecLayoutFields m_FieldsShown; //And any extra keys needed by shown fields.
+};
+
+} //namespace Glom
+
+#endif //BASE_DB_TABLE__DATA_READONLY_H
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f5b7a03..b6b0ae4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@
glom/application.cc
glom/base_db.cc
glom/base_db_table_data.cc
+glom/base_db_table_data_readonly.cc
glom/box_reports.cc
glom.desktop.in.in
glom/dialog_connection.cc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]