Commit 30defb47 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

make public and init target_sheet in the expr case too.

2006-12-04  Jody Goldberg <jody@gnome.org>

	* src/sheet-filter.c (gnm_filter_combo_apply) : make public and init
	  target_sheet in the expr case too.
	(gnm_filter_set_condition) : revert the earlier change from apply ->
	  target_sheet.  We do not need that flexibility here.
	* src/widgets/gnm-filter-combo-foo-view.c (fcombo_fill_model) : Create
	  a temporary sheet and apply the filter to that so that we can list
	  only the elements filtered by other fields.
parent c31b7086
......@@ -17,9 +17,6 @@ Review
Release Critical
----------------
- Audit all calls to gtk_tree_view_new_with_model to ensure that model is
unrefed.
http://bugzilla.gnome.org/show_bug.cgi?id=322096
- mis-export of array expr
......@@ -394,8 +391,8 @@ Architecture Changes
12.3.3.1) SAX (DONE)
12.3.3.3) DOM (DONE)
12.3.3) Add to .xsd schema (DONE)
12.4) XLS
12.4.1) import
12.4) XLS (DONE)
12.4.1) import (DONE)
12.4.2) export (DONE)
12.5) XLSX
12.5.1) import
......@@ -698,7 +695,7 @@ Short Term Goals
21.39) Look at merging style-condition and filter
21.40) col selector to autofilter dialog ala OOo
21.41) RTL (see 9.8) (DONE)
21.42) Only list unfiltered results in combo
21.42) Only list unfiltered results in combo (DONE)
21.43) Gnumeric XML (DONE)
21.43.1) import (DONE)
21.43.1.1) SAX (DONE)
......@@ -707,15 +704,17 @@ Short Term Goals
21.43.2.1) SAX (DONE)
21.43.2.2) DOM (DONE)
21.43.3) Add to .xsd schema (DONE)
21.44) XLS (DONE)
21.44.1) import (DONE)
21.44.2) export (DONE)
21.45) XLSX
21.45.1) import
21.45.2) export
21.46) ODF
21.46.1) import
21.46.2) export
21.48) combo should only list unfiltered items
21.49) Find Leak (DONE)
21.50) Duplication for sheet copy (DONE)
21.47) Find Leak (DONE)
21.48) Duplication for sheet copy (DONE)
22) Validate from List
22.1) Implement (DONE)
......
2006-12-04 Jody Goldberg <jody@gnome.org>
* src/sheet-filter.c (gnm_filter_combo_apply) : make public and init
target_sheet in the expr case too.
(gnm_filter_set_condition) : revert the earlier change from apply ->
target_sheet. We do not need that flexibility here.
* src/widgets/gnm-filter-combo-foo-view.c (fcombo_fill_model) : Create
a temporary sheet and apply the filter to that so that we can list
only the elements filtered by other fields.
2006-12-02 Jody Goldberg <jody@gnome.org>
* src/expr.c (gnm_expr_top_relocate) : don't init rinfo::from_inside
......
......@@ -16,6 +16,7 @@ Jody:
- set initial selection for validate from list
- Home/End jumps to top bottom.
- Fix in RTL mode.
- List items unfiltered by other active conditions in combo.
* Fix .gnumeric import of col/row groupings. [#380015]
* SAX import for autofilters
* Fix XSD schema
......@@ -25,6 +26,7 @@ Jody:
- Make it validate
* Start simplifying the object anchor types for xlsx.
* Fix RTL text display.
* Fix a collection of dialog leaks.
Morten:
* Add automatic test framework.
......
......@@ -5228,7 +5228,7 @@ excel_read_AUTOFILTER (BiffQuery *q, ExcelReadSheet *esheet)
}
gnm_filter_set_condition (filter,
GSF_LE_GET_GUINT16 (q->data), cond, NULL);
GSF_LE_GET_GUINT16 (q->data), cond, FALSE);
}
void
......
......@@ -158,7 +158,7 @@ cb_autofilter_ok (G_GNUC_UNUSED GtkWidget *button,
}
if (cond != NULL) {
gnm_filter_set_condition (state->filter, state->field,
cond, state->filter->sheet);
cond, TRUE);
sheet_update (state->filter->sheet);
}
......
......@@ -15,5 +15,6 @@ typedef struct {
#define GNM_FILTER_COMBO(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNM_FILTER_COMBO_TYPE, GnmFilterCombo))
GType gnm_filter_combo_get_type (void);
void gnm_filter_combo_apply (GnmFilterCombo *fcombo, Sheet *target_sheet);
#endif /* GNM_SHEET_FILTER_COMBO_H */
......@@ -343,29 +343,43 @@ cb_hide_unwanted_percentage (GnmCellIter const *iter,
}
/*****************************************************************************/
static void
filter_field_apply (GnmFilterCombo *fcombo, Sheet *target_sheet)
/**
* gnm_filter_combo_apply :
* @fcombo : #GnmFilterCombo
* @target_sheet : @Sheet
*
**/
void
gnm_filter_combo_apply (GnmFilterCombo *fcombo, Sheet *target_sheet)
{
GnmFilter const *filter = fcombo->filter;
GnmFilterCondition const *cond = fcombo->cond;
int const col = sheet_object_get_range (SHEET_OBJECT (fcombo))->start.col;
int const start_row = filter->r.start.row + 1;
int const end_row = filter->r.end.row;
CellIterFlags iter_flags = CELL_ITER_IGNORE_HIDDEN;
if (start_row > end_row ||
cond == NULL ||
cond->op[0] == GNM_FILTER_UNUSED)
return;
/* For the combo we filter a temporary sheet using the data from filter->sheet
* and need to include everything from the source, because it has a
* different set of conditions */
if (target_sheet != filter->sheet)
iter_flags = CELL_ITER_ALL;
if (0x10 >= (cond->op[0] & GNM_FILTER_OP_TYPE_MASK)) {
FilterExpr data;
data.cond = cond;
data.target_sheet = target_sheet;
filter_expr_init (&data, 0, cond, filter);
if (cond->op[1] != GNM_FILTER_UNUSED)
filter_expr_init (&data, 1, cond, filter);
sheet_foreach_cell_in_range (filter->sheet,
CELL_ITER_IGNORE_HIDDEN,
(target_sheet == filter->sheet) ? CELL_ITER_IGNORE_HIDDEN : CELL_ITER_ALL,
col, start_row, col, end_row,
(CellIterFunc) cb_filter_expr, &data);
......@@ -376,12 +390,12 @@ filter_field_apply (GnmFilterCombo *fcombo, Sheet *target_sheet)
sheet_foreach_cell_in_range (filter->sheet,
CELL_ITER_IGNORE_HIDDEN,
col, start_row, col, end_row,
cb_filter_blanks, target_sheet);
(CellIterFunc) cb_filter_blanks, target_sheet);
else if (cond->op[0] == GNM_FILTER_OP_NON_BLANKS)
sheet_foreach_cell_in_range (filter->sheet,
CELL_ITER_IGNORE_HIDDEN,
col, start_row, col, end_row,
cb_filter_non_blanks, target_sheet);
(CellIterFunc) cb_filter_non_blanks, target_sheet);
else if (0x30 == (cond->op[0] & GNM_FILTER_OP_TYPE_MASK)) {
if (cond->op[0] & 0x2) { /* relative */
FilterPercentage data;
......@@ -575,7 +589,7 @@ gnm_filter_dup (GnmFilter const *src, Sheet *sheet)
gnm_filter_set_condition (dst, i,
gnm_filter_condition_dup (
gnm_filter_get_condition (src, i)),
NULL);
FALSE);
}
sheet->filters = g_slist_prepend (sheet->filters, dst);
......@@ -641,17 +655,18 @@ gnm_filter_get_condition (GnmFilter const *filter, unsigned i)
* gnm_filter_set_condition :
* @filter :
* @i :
* @cond :
* @target_sheet : #Sheet
* @cond : #GnmFilterCondition
* @apply :
*
* Change the @i-th condition of @filter to @cond. If @apply is
* TRUE @filter is used to set the visibility of the rows in @filter::sheet
*
* Change the @i-th condition of @filter to @cond.
* If @target_sheet is non-NULL @filter is used to set the visibility
* of it's rows (using the data from @filter->sheet).
* Absorbs the reference to @cond.
**/
void
gnm_filter_set_condition (GnmFilter *filter, unsigned i,
GnmFilterCondition *cond,
Sheet *target_sheet)
gboolean apply)
{
GnmFilterCombo *fcombo;
gboolean set_infilter = FALSE;
......@@ -670,7 +685,7 @@ gnm_filter_set_condition (GnmFilter *filter, unsigned i,
fcombo->cond = cond;
g_signal_emit (G_OBJECT (fcombo), signals [COND_CHANGED], 0);
if (target_sheet != NULL) {
if (apply) {
/* if there was an existing cond then we need to do
* 1) unfilter everything
* 2) reapply all the filters
......@@ -681,12 +696,12 @@ gnm_filter_set_condition (GnmFilter *filter, unsigned i,
colrow_set_visibility (filter->sheet, FALSE, TRUE,
filter->r.start.row + 1, filter->r.end.row);
for (i = 0 ; i < filter->fields->len ; i++)
filter_field_apply (g_ptr_array_index (filter->fields, i),
target_sheet);
gnm_filter_combo_apply (g_ptr_array_index (filter->fields, i),
filter->sheet);
} else
/* When adding a new cond all we need to do is
* apply that filter */
filter_field_apply (fcombo, target_sheet);
gnm_filter_combo_apply (fcombo, filter->sheet);
}
/* set the activity flag and potentially activate the
......
......@@ -63,7 +63,7 @@ void gnm_filter_remove (GnmFilter *filter);
GnmFilterCondition const *gnm_filter_get_condition (GnmFilter const *filter, unsigned i);
void gnm_filter_set_condition (GnmFilter *filter, unsigned i,
GnmFilterCondition *cond,
Sheet *target_sheet);
gboolean apply);
gboolean gnm_filter_overlaps_range (GnmFilter const *filter, GnmRange const *r);
gboolean gnm_filter_overlaps_range (GnmFilter const *filter, GnmRange const *r);
......
......@@ -167,7 +167,7 @@ filter_show_all (Sheet *sheet)
for (; ptr != NULL ; ptr = ptr->next) {
filter = ptr->data;
for (i = filter->fields->len; i-- > 0 ;)
gnm_filter_set_condition (filter, i, NULL, NULL);
gnm_filter_set_condition (filter, i, NULL, FALSE);
}
/* FIXME: This is slow. We should probably have a linked list
......
......@@ -102,7 +102,7 @@ fcombo_activate (SheetObject *so, GtkWidget *popup, GtkTreeView *list,
if (set_condition) {
gnm_filter_set_condition (fcombo->filter, field_num,
cond, fcombo->filter->sheet);
cond, TRUE);
sheet_update (fcombo->filter->sheet);
}
}
......@@ -112,18 +112,21 @@ typedef struct {
gboolean has_blank;
GHashTable *hash;
GODateConventions const *date_conv;
Sheet *src_sheet;
} UniqueCollection;
static GnmValue *
cb_collect_content (GnmCellIter const *iter, UniqueCollection *uc)
{
if (iter->ri->in_filter)
return NULL;
if (gnm_cell_is_blank (iter->cell))
GnmCell const *cell = (iter->pp.sheet == uc->src_sheet) ? iter->cell
: sheet_cell_get (uc->src_sheet,
iter->pp.eval.col, iter->pp.eval.row);
if (gnm_cell_is_blank (cell))
uc->has_blank = TRUE;
else {
GOFormat const *fmt = gnm_cell_get_format (iter->cell);
GnmValue const *v = iter->cell->value;
GOFormat const *fmt = gnm_cell_get_format (cell);
GnmValue const *v = cell->value;
g_hash_table_replace (uc->hash,
value_dup (v),
format_value (fmt, v, NULL, -1, uc->date_conv));
......@@ -141,17 +144,18 @@ cb_hash_domain (GnmValue *key, gpointer value, gpointer accum)
static GtkListStore *
fcombo_fill_model (SheetObject *so, GtkTreePath **clip, GtkTreePath **select)
{
GnmFilterCombo *fcombo = GNM_FILTER_COMBO (so);
GnmFilterCombo *fcombo = GNM_FILTER_COMBO (so);
GnmFilter const *filter = fcombo->filter;
GnmRange r = filter->r;
Sheet *filtered_sheet;
UniqueCollection uc;
GtkTreeIter iter;
GtkListStore *model;
GPtrArray *sorted = g_ptr_array_new ();
unsigned i;
unsigned i, field_num = fcombo_index (fcombo);
gboolean is_custom = FALSE;
GnmRange r = fcombo->filter->r;
GnmValue const *v;
GnmValue const *cur_val = NULL;
Sheet *sheet = fcombo->filter->sheet;
model = gtk_list_store_new (4,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, gnm_value_get_type ());
......@@ -177,18 +181,27 @@ fcombo_fill_model (SheetObject *so, GtkTreePath **clip, GtkTreePath **select)
r.start.row++;
/* r.end.row = XL actually extend to the first non-empty element in the list */
r.end.col = r.start.col += fcombo_index (fcombo);
r.end.col = r.start.col += field_num;
uc.has_blank = FALSE;
uc.hash = g_hash_table_new_full ((GHashFunc)value_hash, (GEqualFunc)value_equal,
(GDestroyNotify)value_release, (GDestroyNotify)g_free);
uc.date_conv = workbook_date_conv (sheet->workbook);
uc.src_sheet = filter->sheet;
uc.date_conv = workbook_date_conv (uc.src_sheet->workbook);
/* We do not want to show items that are filtered by _other_ fields.
* The cleanest way to do that is
* */
sheet_foreach_cell_in_range (sheet, CELL_ITER_ALL,
* The cleanest way to do that is to create a temporary sheet, apply
* all of the other conditions to it and use that as the source of visibility. */
if (filter->fields->len > 1)
filtered_sheet = sheet_new (uc.src_sheet->workbook, "_DummyFilterPopulate");
else
g_object_ref (filtered_sheet = filter->sheet);
for (i = 0 ; i < filter->fields->len ; i++)
if (i != field_num)
gnm_filter_combo_apply (g_ptr_array_index (filter->fields, i), filtered_sheet);
sheet_foreach_cell_in_range (filtered_sheet, CELL_ITER_IGNORE_HIDDEN,
r.start.col, r.start.row, r.end.col, r.end.row,
(CellIterFunc)&cb_collect_content, &uc);
g_object_unref (filtered_sheet);
g_hash_table_foreach (uc.hash, (GHFunc)cb_hash_domain, sorted);
qsort (&g_ptr_array_index (sorted, 0),
......
......@@ -1427,7 +1427,7 @@ xml_read_filter_field (XmlParseContext *ctxt, xmlNode *field, GnmFilter *filter)
xmlFree (type);
if (cond != NULL)
gnm_filter_set_condition (filter, i, cond, NULL);
gnm_filter_set_condition (filter, i, cond, FALSE);
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment