[goffice] Optionnaly delete trendlines from legend. [#628031]
- From: Jean Bréfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Optionnaly delete trendlines from legend. [#628031]
- Date: Tue, 31 Aug 2010 12:14:04 +0000 (UTC)
commit 7eb9dee9f8cab5d1eefaede30b307a8bb2f2d25f
Author: Jean Brefort <jean brefort normalesup org>
Date: Tue Aug 31 14:12:50 2010 +0200
Optionnaly delete trendlines from legend. [#628031]
ChangeLog | 13 ++++
NEWS | 1 +
goffice/graph/gog-plot.c | 5 +-
goffice/graph/gog-trend-line.c | 120 +++++++++++++++++++++++++++++++++++++++-
goffice/graph/gog-trend-line.h | 1 +
goffice/utils/go-editor.c | 13 ++++
goffice/utils/go-editor.h | 1 +
7 files changed, 152 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9631db9..c2bcaf7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2010-08-31 Jean Brefort <jean brefort normalesup org>
+
+ * goffice/graph/gog-plot.c (gog_plot_update_cardinality),
+ (gog_plot_foreach_elem): optionnaly delete trendlines from legend. [#628031]
+ * goffice/graph/gog-trend-line.c (gog_trend_line_set_property),
+ (gog_trend_line_get_property), (cb_show_in_legend),
+ (gog_trend_line_populate_editor), (gog_trend_line_class_init),
+ (gog_trend_line_init), (gog_trend_line_new_by_type),
+ (gog_trend_line_has_legend): ditto.
+ * goffice/graph/gog-trend-line.h: ditto.
+ * goffice/utils/go-editor.c (go_editor_get_page): new.
+ * goffice/utils/go-editor.h: ditto.
+
2010-08-30 Morten Welinder <terra gnome org>
* goffice/graph/gog-axis.c (map_date_calc_ticks): Simplify and
diff --git a/NEWS b/NEWS
index a86aaf5..865d81f 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Jean:
* Do not crash when displaying cubic spline with no abscissa. [#627507]
* Do not save image filling with no image. [#627690]
* Don't use g_free instead of xmlFree. [#627700]
+ * Optionnaly delete trendlines from legend. [#628031]
Morten:
* Limit formats to sane number of decimals. [#627066]
diff --git a/goffice/graph/gog-plot.c b/goffice/graph/gog-plot.c
index 8fffade..2225100 100644
--- a/goffice/graph/gog-plot.c
+++ b/goffice/graph/gog-plot.c
@@ -510,6 +510,8 @@ gog_plot_update_cardinality (GogPlot *plot, int index_num)
while (children) {
if (GOG_IS_TREND_LINE (children->data))
j++;
+ if (!gog_trend_line_has_legend (GOG_TREND_LINE (children->data)))
+ no_legend++;
children = children->next;
}
}
@@ -595,7 +597,8 @@ gog_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
/* now add the trend lines if any */
children = GOG_OBJECT (ptr->data)->children;
while (children) {
- if (GOG_IS_TREND_LINE (children->data)) {
+ if (GOG_IS_TREND_LINE (children->data) &&
+ gog_trend_line_has_legend (GOG_TREND_LINE (children->data))) {
func (i, go_styled_object_get_style (children->data),
gog_object_get_name (children->data), data);
i++;
diff --git a/goffice/graph/gog-trend-line.c b/goffice/graph/gog-trend-line.c
index 5fcf281..39e6829 100644
--- a/goffice/graph/gog-trend-line.c
+++ b/goffice/graph/gog-trend-line.c
@@ -25,6 +25,99 @@
#include <gsf/gsf-impl-utils.h>
#include <glib/gi18n-lib.h>
+enum {
+ TREND_LINE_PROP_0,
+ TREND_LINE_PROP_HAS_LEGEND
+};
+static GObjectClass *trend_line_parent_klass;
+
+static void
+gog_trend_line_set_property (GObject *obj, guint param_id,
+ GValue const *value, GParamSpec *pspec)
+{
+ gboolean b_tmp;
+
+ switch (param_id) {
+ case TREND_LINE_PROP_HAS_LEGEND :
+ b_tmp = g_value_get_boolean (value);
+ if (GPOINTER_TO_INT (g_object_get_data (obj, "has-legend")) ^ b_tmp) {
+ GogSeries *series = GOG_SERIES (gog_object_get_parent (GOG_OBJECT (obj)));
+ g_object_set_data (obj, "has-legend", GINT_TO_POINTER (b_tmp));
+ if (series->plot != NULL)
+ gog_plot_request_cardinality_update (series->plot);
+ }
+ break;
+
+ default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
+ return; /* NOTE : RETURN */
+ }
+
+ gog_object_emit_changed (GOG_OBJECT (obj), FALSE);
+}
+
+static void
+gog_trend_line_get_property (GObject *obj, guint param_id,
+ GValue *value, GParamSpec *pspec)
+{
+ switch (param_id) {
+ case TREND_LINE_PROP_HAS_LEGEND :
+ g_value_set_boolean (value, GPOINTER_TO_INT (g_object_get_data (obj, "has-legend")));
+ break;
+
+ default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
+ break;
+ }
+}
+
+#ifdef GOFFICE_WITH_GTK
+static void
+cb_show_in_legend (GtkToggleButton *b, GObject *line)
+{
+ g_object_set (line,
+ "has-legend", gtk_toggle_button_get_active (b),
+ NULL);
+}
+
+static void
+gog_trend_line_populate_editor (GogObject *gobj,
+ GOEditor *editor,
+ GogDataAllocator *dalloc,
+ GOCmdContext *cc)
+{
+ GtkWidget *w, *box;
+ GogTrendLine *line = GOG_TREND_LINE (gobj);
+
+ box = go_editor_get_page (editor, _("Properties"));
+ if (!box)
+ box = go_editor_get_page (editor, _("Details"));
+ if (!box) {
+ box = gtk_vbox_new (FALSE, 6);
+ gtk_container_set_border_width (GTK_CONTAINER (box), 12);
+ gtk_widget_show_all (box);
+ go_editor_add_page (editor, box, _("Legend"));
+ }
+ w = gtk_check_button_new_with_mnemonic ("_Show in Legend");
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w),
+ gog_trend_line_has_legend (line));
+ g_signal_connect (G_OBJECT (w),
+ "toggled",
+ G_CALLBACK (cb_show_in_legend), gobj);
+ if (GTK_IS_BOX (box))
+ gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0);
+ else if (GTK_IS_TABLE (box)) {
+ GtkTable *table = GTK_TABLE (box);
+ int nrows, ncols;
+ g_object_get (G_OBJECT (box), "n-rows", &nrows, "n-columns", &ncols, NULL);
+ gtk_table_resize (table, nrows + 1, ncols);
+ gtk_table_attach (table, w, 0, ncols, nrows, nrows + 1, GTK_FILL, 0, 0, 0);
+ } else
+ g_warning ("Unsupported container");
+ gtk_widget_show (w);
+
+ (GOG_OBJECT_CLASS (trend_line_parent_klass)->populate_editor) (gobj, editor, dalloc, cc);
+}
+#endif
+
static void
gog_trend_line_init_style (GogStyledObject *gso, GOStyle *style)
{
@@ -43,13 +136,32 @@ static void
gog_trend_line_class_init (GogObjectClass *gog_klass)
{
GogStyledObjectClass *style_klass = (GogStyledObjectClass *) gog_klass;
+ GObjectClass *gobject_klass = (GObjectClass *) gog_klass;
+ trend_line_parent_klass = g_type_class_peek_parent (gog_klass);
style_klass->init_style = gog_trend_line_init_style;
+#ifdef GOFFICE_WITH_GTK
+ gog_klass->populate_editor = gog_trend_line_populate_editor;
+#endif
gog_klass->type_name = gog_trend_line_type_name;
+ gobject_klass->set_property = gog_trend_line_set_property;
+ gobject_klass->get_property = gog_trend_line_get_property;
+ g_object_class_install_property (gobject_klass, TREND_LINE_PROP_HAS_LEGEND,
+ g_param_spec_boolean ("has-legend",
+ _("Has-legend"),
+ _("Should the trend line show up in legends"),
+ TRUE,
+ GSF_PARAM_STATIC | G_PARAM_READWRITE | GO_PARAM_PERSISTENT));
+}
+
+static void
+gog_trend_line_init (GObject *obj)
+{
+ g_object_set_data (obj, "has-legend", GINT_TO_POINTER (TRUE));
}
GSF_CLASS_ABSTRACT (GogTrendLine, gog_trend_line,
- gog_trend_line_class_init, NULL,
+ gog_trend_line_class_init, gog_trend_line_init,
GOG_TYPE_STYLED_OBJECT)
GogTrendLine *
@@ -65,3 +177,9 @@ gog_trend_line_new_by_type (GogTrendLineType const *type)
(GHFunc) gog_object_set_arg, res);
return res;
}
+
+gboolean
+gog_trend_line_has_legend (GogTrendLine const *line)
+{
+ return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (line), "has-legend"));
+}
diff --git a/goffice/graph/gog-trend-line.h b/goffice/graph/gog-trend-line.h
index db6a010..34b5e42 100644
--- a/goffice/graph/gog-trend-line.h
+++ b/goffice/graph/gog-trend-line.h
@@ -41,6 +41,7 @@ GType gog_trend_line_get_type (void);
GogTrendLine *gog_trend_line_new_by_name (char const *id);
GogTrendLine *gog_trend_line_new_by_type (GogTrendLineType const *type);
+gboolean gog_trend_line_has_legend (GogTrendLine const *line);
G_END_DECLS
diff --git a/goffice/utils/go-editor.c b/goffice/utils/go-editor.c
index b0541f7..e9cc67f 100644
--- a/goffice/utils/go-editor.c
+++ b/goffice/utils/go-editor.c
@@ -192,4 +192,17 @@ go_editor_get_notebook (GOEditor *editor)
return notebook;
}
+GtkWidget *
+go_editor_get_page (GOEditor *editor, char const *name)
+{
+ GSList *ptr;
+ GOEditorPage *page;
+ for (ptr = editor->pages; ptr; ptr = ptr->next) {
+ page = (GOEditorPage *) ptr->data;
+ if (strcmp (page->label, name))
+ return page->widget;
+ }
+
+}
+
#endif
diff --git a/goffice/utils/go-editor.h b/goffice/utils/go-editor.h
index 2f623fd..a4656b5 100644
--- a/goffice/utils/go-editor.h
+++ b/goffice/utils/go-editor.h
@@ -45,6 +45,7 @@ void go_editor_set_store_page (GOEditor *editor, unsigned *store_page);
void go_editor_register_widget (GOEditor *editor, GtkWidget *widget);
GtkWidget *go_editor_get_registered_widget (GOEditor *editor, char const *name);
GtkWidget *go_editor_get_notebook (GOEditor *editor);
+GtkWidget *go_editor_get_page (GOEditor *editor, char const *name);
#endif
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]