Views: finished handling and documenting the conditions for an existing

column to be added to a view
This commit is contained in:
Celine Mercier
2017-08-03 16:32:22 +02:00
parent 644b55b49f
commit a3e81930c2
2 changed files with 29 additions and 13 deletions

View File

@ -2281,18 +2281,30 @@ int obi_view_add_column(Obiview_p view,
obidebug(1, "\nError opening a column to add to a view"); obidebug(1, "\nError opening a column to add to a view");
return -1; return -1;
} }
// Check that, if it's not the first column in the view, the column's line count is at least the view's line count if there's a line selection // - If there is a line selection:
// Otherwise it should be the same line count // - The column's lines_used attribute must be at least the view's line count
// TODO rediscuss. When cloning a view, if there's a line selection associated, // - If there is no line selection:
// when re-adding the columns to the cloned view, it is normal that the columns have a line count greater than the view's. // - If it's the first column in the view:
if (((view->infos)->column_count > 0) // - The view's line count is set to the column's lines_used attribute
&& (((view->line_selection != NULL) && ((column->header)->lines_used < (view->infos)->line_count)) // - If it's not the first column in the view:
|| ((view->line_selection == NULL) && ((column->header)->lines_used != (view->infos)->line_count)))) // - The column's lines_used attribute must be equal to the view's line count
{ if ((view->line_selection != NULL) && ((column->header)->lines_used < (view->infos)->line_count))
{ // - If there is a line selection, the column's lines_used attribute must be at least the view's line count
obi_set_errno(OBIVIEW_ERROR); obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError adding an existing column to a view: the column's line count (%lld) must be at least the view's (%lld) (when there is a line selection)", (column->header)->line_count, (view->infos)->line_count); obidebug(1, "\nError adding an existing column to a view: the column's lines_used attribute (%lld) must be equal to or greater than the view's line count (%lld)", (column->header)->lines_used, (view->infos)->line_count);
return -1; return -1;
} }
else if (view->line_selection == NULL)
{ // If there is no line selection:
if ((view->infos)->column_count == 0) // If it's the first column in the view:
(view->infos)->line_count = (column->header)->lines_used; // The view's line count is set to the column's lines_used attribute
else if ((column->header)->lines_used != (view->infos)->line_count)
{ // If it's not the first column in the view, the column's lines_used attribute must be equal to the view's line count
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError adding an existing column to a view: the column's lines_used attribute (%lld) must be equal to the view's line count (%lld)", (column->header)->lines_used, (view->infos)->line_count);
return -1;
}
}
} }
// Store column pointer in the view structure // Store column pointer in the view structure
@ -2311,10 +2323,6 @@ int obi_view_add_column(Obiview_p view,
// Save column alias // Save column alias
strcpy((((view->infos)->column_references)[(view->infos)->column_count]).alias, alias); strcpy((((view->infos)->column_references)[(view->infos)->column_count]).alias, alias);
// If it's the first column of the view, set the view's line count to the column's line count, except if there's a line selection associated
if (((view->infos)->column_count == 0) && (view->line_selection == NULL))
(view->infos)->line_count = (column->header)->lines_used;
// Update column count in view // Update column count in view
(view->infos)->column_count++; (view->infos)->column_count++;

View File

@ -340,6 +340,14 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name);
/** /**
* @brief Adds a column to a view. * @brief Adds a column to a view.
* *
* - If there is a line selection:
* - The column's lines_used attribute must be at least the view's line count
* - If there is no line selection:
* - If it's the first column in the view:
* - The view's line count is set to the column's lines_used attribute
* - If it's not the first column in the view:
* - The column's lines_used attribute must be equal to the view's line count
*
* @warning The view must be writable. * @warning The view must be writable.
* *
* @param view A pointer on the view. * @param view A pointer on the view.