Refactored the data validation struct.

Refactored the data validation struct to remove hidden fields.

See #252
This commit is contained in:
John McNamara 2019-11-17 11:27:56 +00:00
parent 3e3ce69aab
commit aacdd525a5
3 changed files with 37 additions and 13 deletions

View File

@ -49,7 +49,7 @@ ifndef USE_STANDARD_TMPFILE
endif
# Run the unit tests.
test : all test_functional test_unit
test : all test_unit test_functional
# Test for C++ const correctness on APIs.
test_const : all

View File

@ -259,7 +259,7 @@ struct lxw_table_rows {
STAILQ_HEAD(lxw_merged_ranges, lxw_merged_range);
STAILQ_HEAD(lxw_selections, lxw_selection);
STAILQ_HEAD(lxw_data_validations, lxw_data_validation);
STAILQ_HEAD(lxw_data_validations, lxw_data_val_obj);
STAILQ_HEAD(lxw_image_props, lxw_object_properties);
STAILQ_HEAD(lxw_chart_props, lxw_object_properties);
@ -405,8 +405,6 @@ typedef struct lxw_data_validation {
*/
uint8_t dropdown;
uint8_t is_between;
/**
* This parameter is used to set the limiting value to which the criteria
* is applied using a whole or decimal number.
@ -519,11 +517,38 @@ typedef struct lxw_data_validation {
*/
char *error_message;
} lxw_data_validation;
/* A copy of lxw_data_validation which is used internally and which contains
* some additional fields.
*/
typedef struct lxw_data_val_obj {
uint8_t validate;
uint8_t criteria;
uint8_t ignore_blank;
uint8_t show_input;
uint8_t show_error;
uint8_t error_type;
uint8_t dropdown;
double value_number;
char *value_formula;
char **value_list;
double minimum_number;
char *minimum_formula;
lxw_datetime minimum_datetime;
double maximum_number;
char *maximum_formula;
lxw_datetime maximum_datetime;
char *input_title;
char *input_message;
char *error_title;
char *error_message;
char sqref[LXW_MAX_CELL_RANGE_LENGTH];
STAILQ_ENTRY (lxw_data_validation) list_pointers;
STAILQ_ENTRY (lxw_data_val_obj) list_pointers;
} lxw_data_val_obj;
} lxw_data_validation;
/**
* @brief Options for inserted images.

View File

@ -281,7 +281,7 @@ _free_object_properties(lxw_object_properties *object_property)
* Free a worksheet data_validation.
*/
STATIC void
_free_data_validation(lxw_data_validation *data_validation)
_free_data_validation(lxw_data_val_obj *data_validation)
{
if (!data_validation)
return;
@ -309,7 +309,7 @@ lxw_worksheet_free(lxw_worksheet *worksheet)
lxw_merged_range *merged_range;
lxw_object_properties *object_props;
lxw_selection *selection;
lxw_data_validation *data_validation;
lxw_data_val_obj *data_validation;
lxw_rel_tuple *relationship;
if (!worksheet)
@ -3568,7 +3568,7 @@ _worksheet_write_formula2_str(lxw_worksheet *self, char *str)
*/
STATIC void
_worksheet_write_data_validation(lxw_worksheet *self,
lxw_data_validation *validation)
lxw_data_val_obj *validation)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
@ -3717,7 +3717,7 @@ _worksheet_write_data_validations(lxw_worksheet *self)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
lxw_data_validation *data_validation;
lxw_data_val_obj *data_validation;
if (self->num_validations == 0)
return;
@ -5805,7 +5805,7 @@ worksheet_data_validation_range(lxw_worksheet *self, lxw_row_t first_row,
lxw_col_t last_col,
lxw_data_validation *validation)
{
lxw_data_validation *copy;
lxw_data_val_obj *copy;
uint8_t is_between = LXW_FALSE;
uint8_t is_formula = LXW_FALSE;
uint8_t has_criteria = LXW_TRUE;
@ -5961,7 +5961,7 @@ worksheet_data_validation_range(lxw_worksheet *self, lxw_row_t first_row,
return err;
/* Create a copy of the parameters from the user data validation. */
copy = calloc(1, sizeof(lxw_data_validation));
copy = calloc(1, sizeof(lxw_data_val_obj));
GOTO_LABEL_ON_MEM_ERROR(copy, mem_error);
/* Create the data validation range. */
@ -5976,7 +5976,6 @@ worksheet_data_validation_range(lxw_worksheet *self, lxw_row_t first_row,
copy->value_number = validation->value_number;
copy->error_type = validation->error_type;
copy->dropdown = validation->dropdown;
copy->is_between = is_between;
if (has_criteria)
copy->criteria = validation->criteria;