[glom] export: Deal with lists of const LayoutItems.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] export: Deal with lists of const LayoutItems.
- Date: Fri, 18 Mar 2016 20:58:10 +0000 (UTC)
commit 62a2ec1d634de9f2f8274c3dc7e639770b95c5b3
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Mar 18 13:50:31 2016 +0100
export: Deal with lists of const LayoutItems.
Also making get_table_fields_to_show_for_sequence() take a list of const,
which leads to more const correctness in its callers.
glom/appwindow.cc | 3 ++-
glom/filechooser_export.cc | 4 ++--
glom/filechooser_export.h | 6 +++---
glom/frame_glom.cc | 10 ++++++----
glom/libglom/db_utils_export.cc | 4 ++--
glom/libglom/db_utils_export.h | 4 ++--
glom/libglom/document/document.h | 1 +
glom/libglom/layout_utils.cc | 17 +++++++++--------
glom/libglom/layout_utils.h | 3 ++-
glom/mode_data/box_data.cc | 7 +++++--
glom/mode_data/box_data_portal.cc | 2 +-
glom/mode_design/layout/dialog_layout_export.cc | 6 +++---
glom/mode_design/layout/dialog_layout_export.h | 4 ++--
glom/print_layout/canvas_print_layout.cc | 4 ++--
glom/print_layout/canvas_print_layout.h | 2 +-
15 files changed, 43 insertions(+), 34 deletions(-)
---
diff --git a/glom/appwindow.cc b/glom/appwindow.cc
index 38e17bb..e8010ae 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -2049,7 +2049,8 @@ void AppWindow::on_menu_file_save_as_example()
Document::type_example_rows example_rows;
FoundSet found_set;
found_set.m_table_name = table_name;
- DbUtils::export_data_to_vector(document, example_rows, found_set, sequence);
+ auto const_sequence = Utils::const_list(sequence);
+ DbUtils::export_data_to_vector(document, example_rows, found_set, const_sequence);
//std::cout << " debug after row_text=" << row_text << std::endl;
document->set_table_example_data(table_name, example_rows);
diff --git a/glom/filechooser_export.cc b/glom/filechooser_export.cc
index aaabea5..b23c258 100644
--- a/glom/filechooser_export.cc
+++ b/glom/filechooser_export.cc
@@ -72,7 +72,7 @@ FileChooser_Export::~FileChooser_Export()
#endif //GLOM_ENABLE_CLIENT_ONLY
}
-void FileChooser_Export::set_export_layout(const Document::type_list_layout_groups& layout_groups, const
Glib::ustring& table_name, const std::shared_ptr<Document>& document)
+void FileChooser_Export::set_export_layout(const Document::type_list_const_layout_groups& layout_groups,
const Glib::ustring& table_name, const std::shared_ptr<Document>& document)
{
m_layout_groups = layout_groups;
m_table_name = table_name;
@@ -103,7 +103,7 @@ void FileChooser_Export::on_dialog_layout_hide()
}
#endif //GLOM_ENABLE_CLIENT_ONLY
-void FileChooser_Export::get_layout_groups(Document::type_list_layout_groups& layout_groups) const
+void FileChooser_Export::get_layout_groups(Document::type_list_const_layout_groups& layout_groups) const
{
layout_groups = m_layout_groups;
}
diff --git a/glom/filechooser_export.h b/glom/filechooser_export.h
index 51719d6..7a89065 100644
--- a/glom/filechooser_export.h
+++ b/glom/filechooser_export.h
@@ -36,9 +36,9 @@ public:
FileChooser_Export();
virtual ~FileChooser_Export();
- void set_export_layout(const Document::type_list_layout_groups& layout_groups, const Glib::ustring&
table_name, const std::shared_ptr<Document>& document);
+ void set_export_layout(const Document::type_list_const_layout_groups& layout_groups, const Glib::ustring&
table_name, const std::shared_ptr<Document>& document);
- void get_layout_groups(Document::type_list_layout_groups& layout_groups) const;
+ void get_layout_groups(Document::type_list_const_layout_groups& layout_groups) const;
private:
@@ -57,7 +57,7 @@ private:
Glib::ustring m_table_name;
- Document::type_list_layout_groups m_layout_groups;
+ Document::type_list_const_layout_groups m_layout_groups;
std::shared_ptr<Document> m_document;
};
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 74b79b2..a8d33d9 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -558,7 +558,9 @@ void Frame_Glom::on_menu_file_export()
FileChooser_Export dialog;
dialog.set_transient_for(*get_app_window());
dialog.set_do_overwrite_confirmation();
- dialog.set_export_layout(mapGroupSequence, m_table_name, get_document());
+
+ auto const_sequence = Utils::const_list(mapGroupSequence);
+ dialog.set_export_layout(const_sequence, m_table_name, get_document());
const int response = dialog.run();
dialog.hide();
@@ -571,8 +573,8 @@ void Frame_Glom::on_menu_file_export()
filepath = UiUtils::get_filepath_with_extension(filepath, "csv");
- dialog.get_layout_groups(mapGroupSequence);
- //std::cout << "DEBUG 0: mapGroupSequence.size()=" << mapGroupSequence.size() << std::endl;
+ dialog.get_layout_groups(const_sequence);
+ //std::cout << "DEBUG 0: const_sequence.size()=" << const_sequence.size() << std::endl;
//const int index_primary_key = fieldsSequence.size() - 1;
@@ -585,7 +587,7 @@ void Frame_Glom::on_menu_file_export()
return;
}
- DbUtils::export_data_to_stream(document, the_stream, found_set, mapGroupSequence);
+ DbUtils::export_data_to_stream(document, the_stream, found_set, const_sequence);
}
void Frame_Glom::on_menu_file_import()
diff --git a/glom/libglom/db_utils_export.cc b/glom/libglom/db_utils_export.cc
index 785cd9a..ce51da1 100644
--- a/glom/libglom/db_utils_export.cc
+++ b/glom/libglom/db_utils_export.cc
@@ -36,7 +36,7 @@ namespace DbUtils
//TODO: Reduce copy/pasting in these export_data_to_*() methods:
-void export_data_to_vector(const std::shared_ptr<Document>& document, Document::type_example_rows&
the_vector, const FoundSet& found_set, const Document::type_list_layout_groups& sequence)
+void export_data_to_vector(const std::shared_ptr<Document>& document, Document::type_example_rows&
the_vector, const FoundSet& found_set, const Document::type_list_const_layout_groups& sequence)
{
auto fieldsSequence = Utils::get_table_fields_to_show_for_sequence(document, found_set.m_table_name,
sequence);
@@ -86,7 +86,7 @@ void export_data_to_vector(const std::shared_ptr<Document>& document, Document::
}
}
-void export_data_to_stream(const std::shared_ptr<Document>& document, std::ostream& the_stream, const
FoundSet& found_set, const Document::type_list_layout_groups& sequence)
+void export_data_to_stream(const std::shared_ptr<Document>& document, std::ostream& the_stream, const
FoundSet& found_set, const Document::type_list_const_layout_groups& sequence)
{
auto fieldsSequence = Utils::get_table_fields_to_show_for_sequence(document, found_set.m_table_name,
sequence);
diff --git a/glom/libglom/db_utils_export.h b/glom/libglom/db_utils_export.h
index 77ccebe..89acaca 100644
--- a/glom/libglom/db_utils_export.h
+++ b/glom/libglom/db_utils_export.h
@@ -31,9 +31,9 @@ namespace Glom
namespace DbUtils
{
-void export_data_to_vector(const std::shared_ptr<Document>& document, Document::type_example_rows&
the_vector, const FoundSet& found_set, const Document::type_list_layout_groups& sequence);
+void export_data_to_vector(const std::shared_ptr<Document>& document, Document::type_example_rows&
the_vector, const FoundSet& found_set, const Document::type_list_const_layout_groups& sequence);
-void export_data_to_stream(const std::shared_ptr<Document>& document, std::ostream& the_stream, const
FoundSet& found_set, const Document::type_list_layout_groups& sequence);
+void export_data_to_stream(const std::shared_ptr<Document>& document, std::ostream& the_stream, const
FoundSet& found_set, const Document::type_list_const_layout_groups& sequence);
} //namespace DbUtils
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index 4b7657c..e3647a1 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -230,6 +230,7 @@ public:
typedef std::vector< std::shared_ptr<LayoutGroup> > type_list_layout_groups;
+ typedef std::vector< std::shared_ptr<const LayoutGroup> > type_list_const_layout_groups;
/** Get the layout groups for a layout.
* @param layout_name The name of the layout, such as list or details.
diff --git a/glom/libglom/layout_utils.cc b/glom/libglom/layout_utils.cc
index a941728..ae1bfa6 100644
--- a/glom/libglom/layout_utils.cc
+++ b/glom/libglom/layout_utils.cc
@@ -160,13 +160,13 @@ static bool get_field_primary_key_index_for_fields(const Utils::type_vec_fields&
return false; //Not found.
}
-static void get_table_fields_to_show_for_sequence_add_group(const std::shared_ptr<const Document>& document,
const Glib::ustring& table_name, const Privileges& table_privs, const Utils::type_vec_fields& all_db_fields,
const std::shared_ptr<LayoutGroup>& group, Utils::type_vecConstLayoutFields& vecFields)
+static void get_table_fields_to_show_for_sequence_add_group(const std::shared_ptr<const Document>& document,
const Glib::ustring& table_name, const Privileges& table_privs, const Utils::type_vec_fields& all_db_fields,
const std::shared_ptr<const LayoutGroup>& group, Utils::type_vecConstLayoutFields& vecFields)
{
//g_warning("Box_Data::get_table_fields_to_show_for_sequence_add_group(): table_name=%s,
all_db_fields.size()=%d, group->name=%s", table_name.c_str(), all_db_fields.size(),
group->get_name().c_str());
for(const auto& item : group->get_items())
{
- auto item_field = std::dynamic_pointer_cast<LayoutItem_Field>(item);
+ auto item_field = std::dynamic_pointer_cast<const LayoutItem_Field>(item);
if(item_field)
{
//Get the field info:
@@ -178,10 +178,10 @@ static void get_table_fields_to_show_for_sequence_add_group(const std::shared_pt
auto field = DbUtils::get_fields_for_table_one_field(document,
item_field->get_table_used(table_name), item->get_name());
if(field)
{
- auto layout_item = item_field;
+ //TODO: Avoid the clone just to remove the constness?
+ auto layout_item = glom_sharedptr_clone(item_field);
layout_item->set_full_field_details(field); //Fill in the full field information for later.
-
//TODO_Performance: We do this once for each related field, even if there are 2 from the same
table:
const auto privs_related = Privs::get_current_privs(item_field->get_table_used(table_name));
layout_item->m_priv_view = privs_related.m_view;
@@ -201,7 +201,8 @@ static void get_table_fields_to_show_for_sequence_add_group(const std::shared_pt
//If the field does not exist anymore then we won't try to show it:
if(iterFind != all_db_fields.end() )
{
- auto layout_item = item_field;
+ //TODO: Avoid the clone just to remove the constness?
+ auto layout_item = glom_sharedptr_clone(item_field);
layout_item->set_full_field_details(*iterFind); //Fill the LayoutItem with the full field
information.
//std::cout << "debug: " << G_STRFUNC << ": name=" << layout_item->get_name() << std::endl;
@@ -216,10 +217,10 @@ static void get_table_fields_to_show_for_sequence_add_group(const std::shared_pt
}
else
{
- auto item_group = std::dynamic_pointer_cast<LayoutGroup>(item);
+ auto item_group = std::dynamic_pointer_cast<const LayoutGroup>(item);
if(item_group)
{
- auto item_portal = std::dynamic_pointer_cast<LayoutItem_Portal>(item);
+ auto item_portal = std::dynamic_pointer_cast<const LayoutItem_Portal>(item);
if(!item_portal) //Do not recurse into portals. They are filled by means of a separate SQL query.
{
//Recurse:
@@ -237,7 +238,7 @@ static void get_table_fields_to_show_for_sequence_add_group(const std::shared_pt
} //anonymous namespace
-Utils::type_vecConstLayoutFields Utils::get_table_fields_to_show_for_sequence(const std::shared_ptr<const
Document>& document, const Glib::ustring& table_name, const Document::type_list_layout_groups&
mapGroupSequence)
+Utils::type_vecConstLayoutFields Utils::get_table_fields_to_show_for_sequence(const std::shared_ptr<const
Document>& document, const Glib::ustring& table_name, const Document::type_list_const_layout_groups&
mapGroupSequence)
{
//Get field definitions from the database, with corrections from the document:
auto all_fields = DbUtils::get_fields_for_table(document, table_name);
diff --git a/glom/libglom/layout_utils.h b/glom/libglom/layout_utils.h
index cd57ad6..27bf77e 100644
--- a/glom/libglom/layout_utils.h
+++ b/glom/libglom/layout_utils.h
@@ -57,7 +57,8 @@ LayoutGroup::type_list_const_items get_layout_items_plus_primary_key(const Layou
*/
LayoutGroup::type_list_items get_layout_items_plus_primary_key(const LayoutGroup::type_list_items& items,
const std::shared_ptr<const Document>& document, const Glib::ustring& table_name);
-type_vecConstLayoutFields get_table_fields_to_show_for_sequence(const std::shared_ptr<const Document>&
document, const Glib::ustring& table_name, const Document::type_list_layout_groups& mapGroupSequence);
+
+type_vecConstLayoutFields get_table_fields_to_show_for_sequence(const std::shared_ptr<const Document>&
document, const Glib::ustring& table_name, const Document::type_list_const_layout_groups& mapGroupSequence);
/**
diff --git a/glom/mode_data/box_data.cc b/glom/mode_data/box_data.cc
index 6789bf5..f035c15 100644
--- a/glom/mode_data/box_data.cc
+++ b/glom/mode_data/box_data.cc
@@ -243,8 +243,11 @@ Box_Data::type_vecConstLayoutFields Box_Data::get_table_fields_to_show(const Gli
const auto pDoc = std::dynamic_pointer_cast<const Document>(get_document());
if(pDoc)
{
- Document::type_list_layout_groups mapGroupSequence =
pDoc->get_data_layout_groups_plus_new_fields(m_layout_name, table_name, m_layout_platform);
- return Utils::get_table_fields_to_show_for_sequence(pDoc, table_name, mapGroupSequence);
+ const auto mapGroupSequence = pDoc->get_data_layout_groups_plus_new_fields(m_layout_name, table_name,
m_layout_platform);
+
+ //TODO: Avoid the copy just for the constness.
+ const auto const_sequence = Utils::const_list(mapGroupSequence);
+ return Utils::get_table_fields_to_show_for_sequence(pDoc, table_name, const_sequence);
}
else
return type_vecConstLayoutFields();
diff --git a/glom/mode_data/box_data_portal.cc b/glom/mode_data/box_data_portal.cc
index 24a3426..06356e9 100644
--- a/glom/mode_data/box_data_portal.cc
+++ b/glom/mode_data/box_data_portal.cc
@@ -187,7 +187,7 @@ Box_Data_Portal::type_vecConstLayoutFields Box_Data_Portal::get_fields_to_show()
const auto document = get_document();
if(document && m_portal)
{
- Document::type_list_layout_groups mapGroups;
+ Document::type_list_const_layout_groups mapGroups;
mapGroups.emplace_back(m_portal);
auto relationship = m_portal->get_relationship();
diff --git a/glom/mode_design/layout/dialog_layout_export.cc b/glom/mode_design/layout/dialog_layout_export.cc
index 0ab77c6..c8c6fe6 100644
--- a/glom/mode_design/layout/dialog_layout_export.cc
+++ b/glom/mode_design/layout/dialog_layout_export.cc
@@ -92,7 +92,7 @@ Dialog_Layout_Export::Dialog_Layout_Export(BaseObjectType* cobject, const Glib::
show_all_children();
}
-void Dialog_Layout_Export::set_layout_groups(Document::type_list_layout_groups& mapGroups, const
std::shared_ptr<Document>& document, const Glib::ustring& table_name)
+void Dialog_Layout_Export::set_layout_groups(Document::type_list_const_layout_groups& mapGroups, const
std::shared_ptr<Document>& document, const Glib::ustring& table_name)
{
Base_DB::set_document(document);
@@ -214,12 +214,12 @@ void Dialog_Layout_Export::on_button_down()
move_treeview_selection_down(m_treeview_fields, m_ColumnsFields.m_col_sequence);
}
-void Dialog_Layout_Export::get_layout_groups(Document::type_list_layout_groups& layout_groups) const
+void Dialog_Layout_Export::get_layout_groups(Document::type_list_const_layout_groups& layout_groups) const
{
//Get the data from the TreeView and store it in the document:
//Get the groups and their fields:
- Document::type_list_layout_groups groups;
+ Document::type_list_const_layout_groups groups;
//Add the fields to the one group:
auto others = std::make_shared<LayoutGroup>();
diff --git a/glom/mode_design/layout/dialog_layout_export.h b/glom/mode_design/layout/dialog_layout_export.h
index c15f705..efa48f9 100644
--- a/glom/mode_design/layout/dialog_layout_export.h
+++ b/glom/mode_design/layout/dialog_layout_export.h
@@ -40,9 +40,9 @@ public:
* @param table_name The table name.
* @param table_fields: The actual fields in the table, in case the document does not yet know about them
all.
*/
- void set_layout_groups(Document::type_list_layout_groups& mapGroups, const std::shared_ptr<Document>&
document, const Glib::ustring& table_name);
+ void set_layout_groups(Document::type_list_const_layout_groups& mapGroups, const
std::shared_ptr<Document>& document, const Glib::ustring& table_name);
- void get_layout_groups(Document::type_list_layout_groups& layout_groups) const;
+ void get_layout_groups(Document::type_list_const_layout_groups& layout_groups) const;
private:
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index fc30542..d36d694 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -1055,7 +1055,7 @@ void Canvas_PrintLayout::set_grid_gap(double gap)
m_bounds_group->lower();
}
-Base_DB::type_vecConstLayoutFields Canvas_PrintLayout::get_portal_fields_to_show(const
std::shared_ptr<LayoutItem_Portal>& portal)
+Base_DB::type_vecConstLayoutFields Canvas_PrintLayout::get_portal_fields_to_show(const std::shared_ptr<const
LayoutItem_Portal>& portal)
{
const auto document = get_document();
if(!document)
@@ -1063,7 +1063,7 @@ Base_DB::type_vecConstLayoutFields Canvas_PrintLayout::get_portal_fields_to_show
if(document && portal)
{
- Document::type_list_layout_groups mapGroups;
+ Document::type_list_const_layout_groups mapGroups;
mapGroups.emplace_back(portal);
auto relationship = portal->get_relationship();
diff --git a/glom/print_layout/canvas_print_layout.h b/glom/print_layout/canvas_print_layout.h
index c139c01..f922ce4 100644
--- a/glom/print_layout/canvas_print_layout.h
+++ b/glom/print_layout/canvas_print_layout.h
@@ -110,7 +110,7 @@ private:
void fill_with_data_portal(const Glib::RefPtr<CanvasLayoutItem>& canvas_item, const Gnome::Gda::Value&
foreign_key_value);
static void set_canvas_item_field_value(const Glib::RefPtr<Goocanvas::Item>& canvas_item, const
std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value);
- type_vecConstLayoutFields get_portal_fields_to_show(const std::shared_ptr<LayoutItem_Portal>& portal);
+ type_vecConstLayoutFields get_portal_fields_to_show(const std::shared_ptr<const LayoutItem_Portal>&
portal);
void create_canvas_layout_item_and_add(const std::shared_ptr<LayoutItem>& layout_item);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]