Add a populated parameter to ag_db_chart_save_new()

If the caller intends to fill the whole struct, this should be set to TRUE
This commit is contained in:
Gergely Polonkai 2014-09-27 23:04:17 +02:00
parent 6656f52959
commit 2177ac2c41
4 changed files with 16 additions and 6 deletions

View File

@ -1997,7 +1997,7 @@ ag_chart_get_db_save(AgChart *chart, gint db_id)
{ {
GsweCoordinates *coords; GsweCoordinates *coords;
AgChartPrivate *priv = ag_chart_get_instance_private(chart); AgChartPrivate *priv = ag_chart_get_instance_private(chart);
AgDbChartSave *save_data = ag_db_chart_save_new(); AgDbChartSave *save_data = ag_db_chart_save_new(TRUE);
GsweTimestamp *timestamp = gswe_moment_get_timestamp(GSWE_MOMENT(chart)); GsweTimestamp *timestamp = gswe_moment_get_timestamp(GSWE_MOMENT(chart));
GEnumClass *house_system_class; GEnumClass *house_system_class;
GEnumValue *house_system_enum; GEnumValue *house_system_enum;

View File

@ -659,6 +659,14 @@ ag_db_chart_save(AgDb *db, AgDbChartSave *save_data, GError **err)
note = G_VALUE_INIT; note = G_VALUE_INIT;
AgDbPrivate *priv = ag_db_get_instance_private(db); AgDbPrivate *priv = ag_db_get_instance_private(db);
if (save_data == NULL) {
g_error("Trying to save a NULL chart!");
}
if (!save_data->populated) {
g_error("Only populated chart data can be saved!");
}
g_value_init(&name, G_TYPE_STRING); g_value_init(&name, G_TYPE_STRING);
g_value_set_string(&name, save_data->name); g_value_set_string(&name, save_data->name);
@ -828,12 +836,13 @@ ag_db_chart_save(AgDb *db, AgDbChartSave *save_data, GError **err)
} }
AgDbChartSave * AgDbChartSave *
ag_db_chart_save_new(void) ag_db_chart_save_new(gboolean populated)
{ {
AgDbChartSave *save_data; AgDbChartSave *save_data;
save_data = g_new0(AgDbChartSave, 1); save_data = g_new0(AgDbChartSave, 1);
save_data->refcount = 1; save_data->refcount = 1;
save_data->populated = populated;
return save_data; return save_data;
} }
@ -874,7 +883,7 @@ ag_db_chart_get_list(AgDb *db, GError **err)
while (gda_data_model_iter_move_next(iter)) { while (gda_data_model_iter_move_next(iter)) {
const GValue *value; const GValue *value;
AgDbChartSave *save_data = ag_db_chart_save_new(); AgDbChartSave *save_data = ag_db_chart_save_new(FALSE);
value = gda_data_model_iter_get_value_at(iter, 0); value = gda_data_model_iter_get_value_at(iter, 0);
save_data->db_id = g_value_get_int(value); save_data->db_id = g_value_get_int(value);
@ -951,7 +960,7 @@ ag_db_chart_get_data_by_id(AgDb *db, guint row_id, GError **err)
return NULL; return NULL;
} }
save_data = ag_db_chart_save_new(); save_data = ag_db_chart_save_new(TRUE);
/* id */ /* id */
value = gda_data_model_get_value_at( value = gda_data_model_get_value_at(

View File

@ -50,6 +50,7 @@ struct _AgDbClass {
typedef struct _AgDbChartSave { typedef struct _AgDbChartSave {
gint db_id; gint db_id;
gboolean populated;
gchar *name; gchar *name;
gchar *country; gchar *country;
gchar *city; gchar *city;
@ -84,7 +85,7 @@ gboolean ag_db_chart_save(AgDb *db,
AgDbChartSave *save_data, AgDbChartSave *save_data,
GError **err); GError **err);
AgDbChartSave *ag_db_chart_save_new(void); AgDbChartSave *ag_db_chart_save_new(gboolean populated);
AgDbChartSave *ag_db_chart_save_ref(AgDbChartSave *save_data); AgDbChartSave *ag_db_chart_save_ref(AgDbChartSave *save_data);

View File

@ -736,7 +736,7 @@ ag_window_recalculate_chart(AgWindow *window, gboolean set_everything)
gtk_spin_button_update(GTK_SPIN_BUTTON(current)); gtk_spin_button_update(GTK_SPIN_BUTTON(current));
} }
edit_data = ag_db_chart_save_new(); edit_data = ag_db_chart_save_new(TRUE);
edit_data->db_id = db_id; edit_data->db_id = db_id;