File: gwyresultsexport.c

package info (click to toggle)
gwyddion 2.62-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 51,952 kB
  • sloc: ansic: 398,486; python: 7,877; sh: 5,492; makefile: 4,723; xml: 3,883; cpp: 1,969; pascal: 418; perl: 154; ruby: 130
file content (835 lines) | stat: -rw-r--r-- 26,009 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
/*
 *  $Id: gwyresultsexport.c 24881 2022-08-12 09:02:19Z yeti-dn $
 *  Copyright (C) 2017-2022 David Necas (Yeti).
 *  E-mail: yeti@gwyddion.net.
 *
 *  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "config.h"
#include <string.h>
#include <libgwydgets/gwycombobox.h>
#include <libgwydgets/gwystock.h>
#include "app.h"
#include "menu.h"
#include "data-browser.h"
#include "gwymoduleutils.h"
#include "gwyresultsexport.h"

enum {
    COPY,
    SAVE,
    FORMAT_CHANGED,
    LAST_SIGNAL
};

struct _GwyResultsExportPrivate {
    GwyResults *results;
    GtkWidget *format;
    GtkWidget *machine;
    gchar *title;
    GwyResultsFormatFunc format_func;
    gpointer format_data;
    gboolean updating;
};

typedef struct _GwyResultsExportPrivate ResultsExportPriv;

static void gwy_results_export_dispose  (GObject *object);
static void gwy_results_export_finalize (GObject *object);
static void gwy_results_export_save_impl(GwyResultsExport *rexport);
static void gwy_results_export_copy_impl(GwyResultsExport *rexport);
static void gwy_results_export_save     (GwyResultsExport *rexport);
static void gwy_results_export_copy     (GwyResultsExport *rexport);
static void update_format_controls      (GwyResultsExport *rexport);
static void machine_changed             (GwyResultsExport *rexport,
                                         GtkToggleButton *toggle);
static void format_changed              (GtkComboBox *combo,
                                         GwyResultsExport *rexport);

static guint results_export_signals[LAST_SIGNAL] = { 0 };

G_DEFINE_TYPE(GwyResultsExport, gwy_results_export, GTK_TYPE_HBOX)

static void
gwy_results_export_class_init(GwyResultsExportClass *klass)
{
    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);

    g_type_class_add_private(klass, sizeof(ResultsExportPriv));

    gobject_class->dispose = gwy_results_export_dispose;
    gobject_class->finalize = gwy_results_export_finalize;
    klass->save = gwy_results_export_save_impl;
    klass->copy = gwy_results_export_copy_impl;

    /* NB: "copy" and "save" signals are created with LAST flag so that user's handlers are run before save_impl() and
     * copy_impl() and have a chance to update the results. */

    /**
     * GwyResultsExport::copy:
     * @rexport: The #GwyResultsExport which received the signal.
     *
     * The ::copy signal is emitted when user presses the Copy button.
     *
     * Since: 2.50
     **/
    results_export_signals[COPY]
        = g_signal_new("copy",
                       G_OBJECT_CLASS_TYPE(gobject_class),
                       G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                       G_STRUCT_OFFSET(GwyResultsExportClass, copy),
                       NULL, NULL,
                       g_cclosure_marshal_VOID__VOID,
                       G_TYPE_NONE, 0);

    /**
     * GwyResultsExport::save:
     * @rexport: The #GwyResultsExport which received the signal.
     *
     * The ::save signal is emitted when user presses the Save button.
     *
     * Since: 2.50
     **/
    results_export_signals[SAVE]
        = g_signal_new("save",
                       G_OBJECT_CLASS_TYPE(gobject_class),
                       G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                       G_STRUCT_OFFSET(GwyResultsExportClass, save),
                       NULL, NULL,
                       g_cclosure_marshal_VOID__VOID,
                       G_TYPE_NONE, 0);

    /**
     * GwyResultsExport::format-changed:
     * @rexport: The #GwyResultsExport which received the signal.
     *
     * The ::format-changed signal is emitted when the selected format changes.
     *
     * Since: 2.50
     **/
    results_export_signals[FORMAT_CHANGED]
        = g_signal_new("format-changed",
                       G_OBJECT_CLASS_TYPE(gobject_class),
                       G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
                       G_STRUCT_OFFSET(GwyResultsExportClass, format_changed),
                       NULL, NULL,
                       g_cclosure_marshal_VOID__VOID,
                       G_TYPE_NONE, 0);
}

static GtkWidget*
create_image_button(GwyResultsExport *rexport,
                    const gchar *stock_id, const gchar *tooltip)
{
    GtkWidget *button;

    button = gtk_button_new();
    gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
    gtk_widget_set_tooltip_text(button, tooltip);
    gtk_container_add(GTK_CONTAINER(button), gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_SMALL_TOOLBAR));
    gtk_box_pack_end(GTK_BOX(rexport), button, FALSE, FALSE, 0);

    return button;
}

static void
gwy_results_export_dispose(GObject *object)
{
    ResultsExportPriv *rexport = ((GwyResultsExport*)object)->priv;
    GWY_OBJECT_UNREF(rexport->results);
    /* FIXME: Can we have the file save dialogue open when we get here? */
}

static void
gwy_results_export_finalize(GObject *object)
{
    ResultsExportPriv *rexport = ((GwyResultsExport*)object)->priv;
    g_free(rexport->title);
}

static GtkWidget*
create_image_toggle(GwyResultsExport *rexport,
                    const gchar *stock_id, const gchar *tooltip,
                    gboolean active)
{
    GtkWidget *button;

    button = gtk_toggle_button_new();
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active);
    gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
    gtk_widget_set_tooltip_text(button, tooltip);
    gtk_container_add(GTK_CONTAINER(button), gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_SMALL_TOOLBAR));
    gtk_box_pack_end(GTK_BOX(rexport), button, FALSE, FALSE, 0);

    return button;
}

static void
gwy_results_export_init(GwyResultsExport *rexport)
{
    ResultsExportPriv *priv;

    priv = G_TYPE_INSTANCE_GET_PRIVATE(rexport, GWY_TYPE_RESULTS_EXPORT, ResultsExportPriv);
    rexport->priv = priv;
    rexport->format = GWY_RESULTS_REPORT_COLON;
    rexport->style = GWY_RESULTS_EXPORT_PARAMETERS;
}

static void
gwy_results_export_save(GwyResultsExport *rexport)
{
    g_signal_emit(rexport, results_export_signals[SAVE], 0);
}

static void
gwy_results_export_copy(GwyResultsExport *rexport)
{
    g_signal_emit(rexport, results_export_signals[COPY], 0);
}

static void
machine_changed(GwyResultsExport *rexport, GtkToggleButton *toggle)
{
    if (rexport->priv->updating)
        return;

    if (gtk_toggle_button_get_active(toggle))
        rexport->format |= GWY_RESULTS_REPORT_MACHINE;
    else
        rexport->format &= ~GWY_RESULTS_REPORT_MACHINE;

    g_signal_emit(rexport, results_export_signals[FORMAT_CHANGED], 0);
}

static void
format_changed(GtkComboBox *combo, GwyResultsExport *rexport)
{
    guint flags;

    if (rexport->priv->updating)
        return;

    flags = (rexport->format & GWY_RESULTS_REPORT_MACHINE);
    rexport->format = gwy_enum_combo_box_get_active(combo);
    rexport->format |= flags;

    g_signal_emit(rexport, results_export_signals[FORMAT_CHANGED], 0);
}

static gchar*
format_report(GwyResultsExport *rexport)
{
    ResultsExportPriv *priv = rexport->priv;

    if (priv->format_func)
        return priv->format_func(priv->format_data);
    if (priv->results)
        return gwy_results_create_report(rexport->priv->results, rexport->format);
    return NULL;
}

static void
gwy_results_export_save_impl(GwyResultsExport *rexport)
{
    GtkWindow *window;
    const gchar *title;
    gchar *text;

    if (!(text = format_report(rexport)))
        return;

    if ((window = (GtkWindow*)gtk_widget_get_toplevel(GTK_WIDGET(rexport)))) {
        if (!GTK_IS_WINDOW(window))
            window = NULL;
    }
    title = rexport->priv->title ? rexport->priv->title : _("Save Results to File");
    gwy_save_auxiliary_data(title, window, -1, text);
    g_free(text);
}

static void
gwy_results_export_copy_impl(GwyResultsExport *rexport)
{
    GtkClipboard *clipboard;
    GdkDisplay *display;
    gchar *text;

    if (!(text = format_report(rexport)))
        return;

    display = gtk_widget_get_display(GTK_WIDGET(rexport));
    clipboard = gtk_clipboard_get_for_display(display, GDK_SELECTION_CLIPBOARD);
    gtk_clipboard_set_text(clipboard, text, -1);
    g_free(text);
}

/**
 * gwy_results_export_new:
 * @format: Format to select.
 *
 * Creates new controls for result set export.
 *
 * Returns: A newly created result set export widget.
 *
 * Since: 2.50
 **/
GtkWidget*
gwy_results_export_new(GwyResultsReportType format)
{
    GwyResultsExport *rexport;
    ResultsExportPriv *priv;

    rexport = g_object_new(GWY_TYPE_RESULTS_EXPORT, NULL);
    priv = rexport->priv;

    rexport->save = create_image_button(rexport, GTK_STOCK_SAVE, _("Save results to a file"));
    rexport->copy = create_image_button(rexport, GTK_STOCK_COPY, _("Copy results to clipboard"));
    g_signal_connect_swapped(rexport->save, "clicked", G_CALLBACK(gwy_results_export_save), rexport);
    g_signal_connect_swapped(rexport->copy, "clicked", G_CALLBACK(gwy_results_export_copy), rexport);

    rexport->format = format;
    priv->updating = TRUE;
    update_format_controls(rexport);
    priv->updating = FALSE;

    return (GtkWidget*)rexport;
}

static void
update_format_controls(GwyResultsExport *rexport)
{
    static const GwyEnum formats[] = {
        { N_("Colon:"), GWY_RESULTS_REPORT_COLON,  },
        { N_("TAB"),    GWY_RESULTS_REPORT_TABSEP, },
        { N_("CSV"),    GWY_RESULTS_REPORT_CSV,    },
    };

    ResultsExportPriv *priv;
    GtkWidget *combo;
    GtkTreeModel *model;
    gint off, copypos, wantnformats, nformats = 0;
    guint base_format;
    gboolean is_machine;

    priv = rexport->priv;

    if (rexport->style == GWY_RESULTS_EXPORT_FIXED_FORMAT) {
        if (priv->format) {
            gtk_widget_destroy(priv->format);
            priv->format = NULL;
        }
        if (priv->machine) {
            gtk_widget_destroy(priv->machine);
            priv->machine = NULL;
        }
        return;
    }

    gtk_container_child_get(GTK_CONTAINER(rexport), rexport->copy, "position", &copypos, NULL);
    if (priv->format) {
        model = gtk_combo_box_get_model(GTK_COMBO_BOX(priv->format));
        nformats = gtk_tree_model_iter_n_children(model, NULL);
    }

    base_format = (rexport->format & ~GWY_RESULTS_REPORT_MACHINE);
    if (rexport->style == GWY_RESULTS_EXPORT_TABULAR_DATA) {
        wantnformats = 2;
        if (base_format == GWY_RESULTS_REPORT_COLON)
            base_format = GWY_RESULTS_REPORT_TABSEP;
    }
    else
        wantnformats = 3;

    if (wantnformats != nformats) {
        off = (wantnformats == 2) ? 1 : 0;
        if (priv->format)
            gtk_widget_destroy(priv->format);
        combo = gwy_enum_combo_box_new(formats + off, wantnformats, G_CALLBACK(format_changed), rexport,
                                       base_format, TRUE);
        priv->format = combo;
        gtk_widget_set_tooltip_text(combo, _("Result formatting"));
        gtk_box_pack_end(GTK_BOX(rexport), combo, FALSE, FALSE, 0);
        /* A bit confusing when packing from end, but +1 seems to work. */
        gtk_box_reorder_child(GTK_BOX(rexport), combo, copypos+1);
    }

    if (!priv->machine) {
        is_machine = rexport->format & GWY_RESULTS_REPORT_MACHINE;
        priv->machine = create_image_toggle(rexport, GWY_STOCK_SCIENTIFIC_NUMBER_FORMAT,
                                            _("Machine-readable format"), is_machine);
        g_signal_connect_swapped(priv->machine, "toggled", G_CALLBACK(machine_changed), rexport);
    }

    /* The format might not changed but was kind of undefined.  Emit a signal
     * to make sure listeneres set the format now. */
    if (!priv->updating)
        g_signal_emit(rexport, results_export_signals[FORMAT_CHANGED], 0);
}

/**
 * gwy_results_export_set_format:
 * @rexport: Controls for result set export.
 * @format: Format to select.
 *
 * Sets the selected format in result set export controls.
 *
 * Since: 2.50
 **/
void
gwy_results_export_set_format(GwyResultsExport *rexport,
                              GwyResultsReportType format)
{
    gboolean for_machine;
    guint base_format;

    g_return_if_fail(GWY_IS_RESULTS_EXPORT(rexport));

    if (format == rexport->format)
        return;

    for_machine = !!(format & GWY_RESULTS_REPORT_MACHINE);
    base_format = (format & ~GWY_RESULTS_REPORT_MACHINE);
    g_return_if_fail(base_format == GWY_RESULTS_REPORT_COLON
                     || base_format == GWY_RESULTS_REPORT_TABSEP
                     || base_format == GWY_RESULTS_REPORT_CSV);

    g_return_if_fail(!rexport->priv->updating);
    rexport->format = format;
    rexport->priv->updating = TRUE;
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rexport->priv->machine), for_machine);
    gwy_enum_combo_box_set_active(GTK_COMBO_BOX(rexport->priv->format), base_format);
    rexport->priv->updating = FALSE;
}

/**
 * gwy_results_export_get_format:
 * @rexport: Controls for result set export.
 *
 * Gets the selected format in result set export controls.
 *
 * Returns: Currently selected format.
 *
 * Since: 2.50
 **/
GwyResultsReportType
gwy_results_export_get_format(GwyResultsExport *rexport)
{
    g_return_val_if_fail(GWY_IS_RESULTS_EXPORT(rexport), 0);
    return rexport->format;
}

/**
 * gwy_results_export_set_results:
 * @rexport: Controls for result set export.
 * @results: Set of reported scalar values.  May be %NULL to unset.
 *
 * Sets the set of scalar values to save or copy by result set export controls.
 *
 * If you supply a result set to save or copy @rexport handles the Save and Copy buttons itself.  So you do not need
 * to connect to the "copy" and "save" signals, except if you need to ensure @results are updated.
 *
 * Since: 2.50
 **/
void
gwy_results_export_set_results(GwyResultsExport *rexport,
                               GwyResults *results)
{
    GwyResults *old;

    g_return_if_fail(GWY_IS_RESULTS_EXPORT(rexport));
    g_return_if_fail(!results || GWY_IS_RESULTS(results));

    if (rexport->priv->results == results)
        return;

    if (results)
        g_object_ref(results);
    old = rexport->priv->results;
    rexport->priv->results = results;
    GWY_OBJECT_UNREF(old);
}

/**
 * gwy_results_export_get_results:
 * @rexport: Controls for result set export.
 *
 * Gets the set of scalar values to save or copy by result set export controls.
 *
 * Returns: The #GwyResults object, or %NULL.
 *
 * Since: 2.50
 **/
GwyResults*
gwy_results_export_get_results(GwyResultsExport *rexport)
{
    g_return_val_if_fail(GWY_IS_RESULTS_EXPORT(rexport), NULL);
    return rexport->priv->results;
}

/**
 * gwy_results_export_set_format_func:
 * @rexport: Controls for result set export.
 * @func: The formatting function.
 * @user_data: Data passed to @func.
 *
 * Sets the report formatting function for result set export controls.
 *
 * Setting the formatting function allows automated handling of Copy and Save buttons, even when there is not
 * #GwyResults object. It is intended to be used with %GWY_RESULTS_EXPORT_FIXED_FORMAT. However, it takes precedence
 * even when a #GwyResults object is set.
 *
 * Since: 2.62
 **/
void
gwy_results_export_set_format_func(GwyResultsExport *rexport,
                                   GwyResultsFormatFunc func,
                                   gpointer user_data)
{
    g_return_if_fail(GWY_IS_RESULTS_EXPORT(rexport));
    rexport->priv->format_func = func;
    rexport->priv->format_data = user_data;
}

/**
 * gwy_results_export_set_title:
 * @rexport: Controls for result set export.
 * @title: File save dialogue title (or %NULL to use the default).
 *
 * Sets the title of file save dialogue for result set export controls.
 *
 * Since: 2.50
 **/
void
gwy_results_export_set_title(GwyResultsExport *rexport,
                             const gchar *title)
{
    g_return_if_fail(GWY_IS_RESULTS_EXPORT(rexport));
    gwy_assign_string(&rexport->priv->title, title);
}

/**
 * gwy_results_export_set_style:
 * @rexport: Controls for result set export.
 * @style: Report style.
 *
 * Sets the report style for result set export controls.
 *
 * The report style determines which controls will be shown.  For %GWY_RESULTS_EXPORT_FIXED_FORMAT only the action
 * buttons are shown. Tabular data (%GWY_RESULTS_EXPORT_TABULAR_DATA) do not have the %GWY_RESULTS_REPORT_COLON
 * option.  The default style %GWY_RESULTS_EXPORT_PARAMETERS have the full controls.
 *
 * Since: 2.50
 **/
void
gwy_results_export_set_style(GwyResultsExport *rexport,
                             GwyResultsExportStyle style)
{
    g_return_if_fail(GWY_IS_RESULTS_EXPORT(rexport));
    rexport->style = style;
    update_format_controls(rexport);
}

/**
 * gwy_results_export_get_style:
 * @rexport: Controls for result set export.
 *
 * Gets the report style for result set export controls.
 *
 * See gwy_results_export_set_style() for discussion.
 *
 * Returns: The style of the results export controls.
 *
 * Since: 2.50
 **/
GwyResultsExportStyle
gwy_results_export_get_style(GwyResultsExport *rexport)
{
    g_return_val_if_fail(GWY_IS_RESULTS_EXPORT(rexport), GWY_RESULTS_EXPORT_PARAMETERS);
    return rexport->style;
}

/**
 * gwy_results_export_set_actions_sensitive:
 * @rexport: Controls for result set export.
 * @sensitive: %TRUE to make the action buttons sensitive, %FALSE to make them insensitive.
 *
 * Makes the action buttons (copy and save) sensitive or insensitive.
 *
 * This is generally preferred to making the entire widget insensitive as the format can be selected independently on
 * whether there is already anything to export.
 *
 * Since: 2.50
 **/
void
gwy_results_export_set_actions_sensitive(GwyResultsExport *rexport,
                                         gboolean sensitive)
{
    g_return_if_fail(GWY_IS_RESULTS_EXPORT(rexport));
    gtk_widget_set_sensitive(rexport->copy, sensitive);
    gtk_widget_set_sensitive(rexport->save, sensitive);
}

static void
fill_result_string_from_container(GwyResults *results, const gchar *id,
                                  GwyContainer *container, GQuark quark)
{
    const guchar *name;

    if (gwy_container_gis_string(container, quark, &name))
        gwy_results_fill_values(results, id, name, NULL);
    else
        gwy_results_set_na(results, id, NULL);
}

/**
 * gwy_results_fill_filename:
 * @results: Set of reported scalar values.
 * @id: Value identifier.
 * @container: Data container corresponding to a file.
 *
 * Fills data file name in a set of reported scalar values.
 *
 * This is a helper function for #GwyResults.  If @container has no file name
 * associated the value @id is set to N.A.
 *
 * Since: 2.50
 **/
void
gwy_results_fill_filename(GwyResults *results,
                          const gchar *id,
                          GwyContainer *container)
{
    g_return_if_fail(GWY_IS_RESULTS(results));
    g_return_if_fail(id);
    g_return_if_fail(GWY_IS_CONTAINER(container));
    fill_result_string_from_container(results, id, container, g_quark_from_static_string("/filename"));
}

/**
 * gwy_results_fill_channel:
 * @results: Set of reported scalar values.
 * @id: Value identifier.
 * @container: Data container corresponding to a file.
 * @i: Channel number.
 *
 * Fills image channel title in a set of reported scalar values.
 *
 * This is a helper function for #GwyResults.  If the image has no title the associated the value @id is set to N.A.
 *
 * Since: 2.50
 **/
void
gwy_results_fill_channel(GwyResults *results,
                         const gchar *id,
                         GwyContainer *container,
                         gint i)
{
    g_return_if_fail(GWY_IS_RESULTS(results));
    g_return_if_fail(id);
    g_return_if_fail(GWY_IS_CONTAINER(container));
    fill_result_string_from_container(results, id, container, gwy_app_get_data_title_key_for_id(i));
}

/**
 * gwy_results_fill_volume:
 * @results: Set of reported scalar values.
 * @id: Value identifier.
 * @container: Data container corresponding to a file.
 * @i: Volume data number.
 *
 * Fills volume data title in a set of reported scalar values.
 *
 * This is a helper function for #GwyResults.  If the volume data have no title the associated the value @id is set to
 * N.A.
 *
 * Since: 2.50
 **/
void
gwy_results_fill_volume(GwyResults *results,
                        const gchar *id,
                        GwyContainer *container,
                        gint i)
{
    g_return_if_fail(GWY_IS_RESULTS(results));
    g_return_if_fail(id);
    g_return_if_fail(GWY_IS_CONTAINER(container));
    fill_result_string_from_container(results, id, container, gwy_app_get_brick_title_key_for_id(i));
}

/**
 * gwy_results_fill_xyz:
 * @results: Set of reported scalar values.
 * @id: Value identifier.
 * @container: Data container corresponding to a file.
 * @i: XYZ data number.
 *
 * Fills XYZ data title in a set of reported scalar values.
 *
 * This is a helper function for #GwyResults.  If the XYZ data have no title the associated the value @id is set to
 * N.A.
 *
 * Since: 2.50
 **/
void
gwy_results_fill_xyz(GwyResults *results,
                     const gchar *id,
                     GwyContainer *container,
                     gint i)
{
    g_return_if_fail(GWY_IS_RESULTS(results));
    g_return_if_fail(id);
    g_return_if_fail(GWY_IS_CONTAINER(container));
    fill_result_string_from_container(results, id, container, gwy_app_get_surface_title_key_for_id(i));
}

/**
 * gwy_results_fill_curve_map:
 * @results: Set of reported scalar values.
 * @id: Value identifier.
 * @container: Data container corresponding to a file.
 * @i: Curve map data number.
 *
 * Fills curve map data title in a set of reported scalar values.
 *
 * This is a helper function for #GwyResults.  If the curve map data have no title the associated the value @id is set
 * to N.A.
 *
 * Since: 2.60
 **/
void
gwy_results_fill_curve_map(GwyResults *results,
                           const gchar *id,
                           GwyContainer *container,
                           gint i)
{
    g_return_if_fail(GWY_IS_RESULTS(results));
    g_return_if_fail(id);
    g_return_if_fail(GWY_IS_CONTAINER(container));
    fill_result_string_from_container(results, id, container, gwy_app_get_lawn_title_key_for_id(i));
}

/**
 * gwy_results_fill_graph:
 * @results: Set of reported scalar values.
 * @id: Value identifier.
 * @graphmodel: A graph model.
 *
 * Fills graph title in a set of reported scalar values.
 *
 * This is a helper function for #GwyResults.
 *
 * Since: 2.53
 **/
void
gwy_results_fill_graph(GwyResults *results,
                       const gchar *id,
                       GwyGraphModel *graphmodel)
{
    gchar *title = NULL;

    g_return_if_fail(GWY_IS_GRAPH_MODEL(graphmodel));
    g_return_if_fail(GWY_IS_RESULTS(results));
    g_return_if_fail(id);

    g_object_get(graphmodel, "title", &title, NULL);
    gwy_results_fill_values(results, id, title, NULL);
    g_free(title);
}

/**
 * gwy_results_fill_graph_curve:
 * @results: Set of reported scalar values.
 * @id: Value identifier.
 * @container: Data container corresponding to a file.
 * @curvemodel: A graph curve model.
 *
 * Fills graph curve description in a set of reported scalar values.
 *
 * This is a helper function for #GwyResults.
 *
 * Since: 2.53
 **/
void
gwy_results_fill_graph_curve(GwyResults *results,
                             const gchar *id,
                             GwyGraphCurveModel *curvemodel)
{
    gchar *title = NULL;

    g_return_if_fail(GWY_IS_GRAPH_CURVE_MODEL(curvemodel));
    g_return_if_fail(GWY_IS_RESULTS(results));
    g_return_if_fail(id);

    g_object_get(curvemodel, "description", &title, NULL);
    gwy_results_fill_values(results, id, title, NULL);
    g_free(title);
}

/**
 * gwy_results_fill_lawn_curve:
 * @results: Set of reported scalar values.
 * @id: Value identifier.
 * @lawn: Curve map data object.
 * @i: Curve number in @lawn.
 *
 * Fills lawn curve description in a set of reported scalar values.
 *
 * This is a helper function for #GwyResults.
 *
 * Since: 2.60
 **/
void
gwy_results_fill_lawn_curve(GwyResults *results,
                            const gchar *id,
                            GwyLawn *lawn,
                            gint i)
{
    const gchar *title;
    gchar *s;

    g_return_if_fail(GWY_IS_LAWN(lawn));
    g_return_if_fail(GWY_IS_RESULTS(results));
    g_return_if_fail(id);
    g_return_if_fail(i >= 0 && i < gwy_lawn_get_n_curves(lawn));

    if ((title = gwy_lawn_get_curve_label(lawn, i)))
        gwy_results_fill_values(results, id, title, NULL);
    else {
        s = g_strdup_printf("%s %d", _("Untitled"), i);
        gwy_results_fill_values(results, id, s, NULL);
        g_free(s);
    }
}

/************************** Documentation ****************************/

/**
 * SECTION:gwyresultsexport
 * @title: GwyResultsExport
 * @short_description: Controls for value set export
 **/

/**
 * GwyResultsFormatFunc:
 * @user_data: Data passed to gwy_results_export_set_format_func().
 *
 * The type of result formatting function.
 *
 * Returns: Formatted report as a newly allocated string. #GwyResultsExport will free it using g_free() after saving
 *          it to a file or copying to the clipboard.
 *
 * Since: 2.62
 **/
typedef gchar* (*GwyResultsFormatFunc)(gpointer user_data);

/* vim: set cin columns=120 tw=118 et ts=4 sw=4 cino=>1s,e0,n0,f0,{0,}0,^0,\:1s,=0,g1s,h0,t0,+1s,c3,(0,u0 : */