1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = libgda-GdaDataModel.html
27  * outPack = gda
28  * outFile = DataModel
29  * strct   = GdaDataModel
30  * realStrct=
31  * ctorStrct=
32  * clss    = DataModel
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = GObject
38  * implements:
39  * prefixes:
40  * 	- gda_data_model_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ListG
48  * 	- gda.FieldAttributes
49  * 	- gda.Row
50  * 	- gda.Value
51  * structWrap:
52  * 	- GList* -> ListG
53  * 	- GdaFieldAttributes* -> FieldAttributes
54  * 	- GdaRow* -> Row
55  * 	- GdaValue* -> Value
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module gda.DataModel;
62 
63 public  import gdac.gdatypes;
64 
65 private import gdac.gda;
66 private import glib.ConstructionException;
67 private import gobject.ObjectG;
68 
69 private import glib.Str;
70 private import glib.ListG;
71 private import gda.FieldAttributes;
72 private import gda.Row;
73 private import gda.Value;
74 
75 
76 private import gobject.ObjectG;
77 
78 /**
79  */
80 public class DataModel : ObjectG
81 {
82 	
83 	/** the main Gtk struct */
84 	protected GdaDataModel* gdaDataModel;
85 	
86 	
87 	/** Get the main Gtk struct */
88 	public GdaDataModel* getDataModelStruct()
89 	{
90 		return gdaDataModel;
91 	}
92 	
93 	
94 	/** the main Gtk struct as a void* */
95 	protected override void* getStruct()
96 	{
97 		return cast(void*)gdaDataModel;
98 	}
99 	
100 	/**
101 	 * Sets our main struct and passes it to the parent class
102 	 */
103 	public this (GdaDataModel* gdaDataModel)
104 	{
105 		super(cast(GObject*)gdaDataModel);
106 		this.gdaDataModel = gdaDataModel;
107 	}
108 	
109 	protected override void setStruct(GObject* obj)
110 	{
111 		super.setStruct(obj);
112 		gdaDataModel = cast(GdaDataModel*)obj;
113 	}
114 	
115 	/** */
116 	this (ListG glist) {
117 		this( cast(GdaDataModel*)glist.data() );
118 	}
119 	
120 	/**
121 	 */
122 	
123 	/**
124 	 * Notifies listeners of the given data model object of changes
125 	 * in the underlying data. Listeners usually will connect
126 	 * themselves to the "changed" signal in the GdaDataModel
127 	 * class, thus being notified of any new data being appended
128 	 * or removed from the data model.
129 	 */
130 	public void changed()
131 	{
132 		// void gda_data_model_changed (GdaDataModel *model);
133 		gda_data_model_changed(gdaDataModel);
134 	}
135 	
136 	/**
137 	 * Emits the 'row_inserted' and 'changed' signals on model.
138 	 * Params:
139 	 * row = row number.
140 	 */
141 	public void rowInserted(int row)
142 	{
143 		// void gda_data_model_row_inserted (GdaDataModel *model,  gint row);
144 		gda_data_model_row_inserted(gdaDataModel, row);
145 	}
146 	
147 	/**
148 	 * Emits the 'row_updated' and 'changed' signals on model.
149 	 * Params:
150 	 * row = row number.
151 	 */
152 	public void rowUpdated(int row)
153 	{
154 		// void gda_data_model_row_updated (GdaDataModel *model,  gint row);
155 		gda_data_model_row_updated(gdaDataModel, row);
156 	}
157 	
158 	/**
159 	 * Emits the 'row_removed' and 'changed' signal on model.
160 	 * Params:
161 	 * row = row number.
162 	 */
163 	public void rowRemoved(int row)
164 	{
165 		// void gda_data_model_row_removed (GdaDataModel *model,  gint row);
166 		gda_data_model_row_removed(gdaDataModel, row);
167 	}
168 	
169 	/**
170 	 * Emits the 'column_inserted' and 'changed' signals on model.
171 	 * Params:
172 	 * col = column number.
173 	 */
174 	public void columnInserted(int col)
175 	{
176 		// void gda_data_model_column_inserted (GdaDataModel *model,  gint col);
177 		gda_data_model_column_inserted(gdaDataModel, col);
178 	}
179 	
180 	/**
181 	 * Emits the 'column_updated' and 'changed' signals on model.
182 	 * Params:
183 	 * col = column number.
184 	 */
185 	public void columnUpdated(int col)
186 	{
187 		// void gda_data_model_column_updated (GdaDataModel *model,  gint col);
188 		gda_data_model_column_updated(gdaDataModel, col);
189 	}
190 	
191 	/**
192 	 * Emits the 'column_removed' and 'changed' signal on model.
193 	 * Params:
194 	 * col = column number.
195 	 */
196 	public void columnRemoved(int col)
197 	{
198 		// void gda_data_model_column_removed (GdaDataModel *model,  gint col);
199 		gda_data_model_column_removed(gdaDataModel, col);
200 	}
201 	
202 	/**
203 	 * Disables notifications of changes on the given data model. To
204 	 * re-enable notifications again, you should call the
205 	 * gda_data_model_thaw function.
206 	 */
207 	public void freeze()
208 	{
209 		// void gda_data_model_freeze (GdaDataModel *model);
210 		gda_data_model_freeze(gdaDataModel);
211 	}
212 	
213 	/**
214 	 * Re-enables notifications of changes on the given data model.
215 	 */
216 	public void thaw()
217 	{
218 		// void gda_data_model_thaw (GdaDataModel *model);
219 		gda_data_model_thaw(gdaDataModel);
220 	}
221 	
222 	/**
223 	 * Returns: the number of rows in the given data model.
224 	 */
225 	public int getNRows()
226 	{
227 		// gint gda_data_model_get_n_rows (GdaDataModel *model);
228 		return gda_data_model_get_n_rows(gdaDataModel);
229 	}
230 	
231 	/**
232 	 * Returns: the number of columns in the given data model.
233 	 */
234 	public int getNColumns()
235 	{
236 		// gint gda_data_model_get_n_columns (GdaDataModel *model);
237 		return gda_data_model_get_n_columns(gdaDataModel);
238 	}
239 	
240 	/**
241 	 * Queries the underlying data model implementation for a description
242 	 * of a given column. That description is returned in the form of
243 	 * a GdaFieldAttributes structure, which contains all the information
244 	 * about the given column in the data model.
245 	 * Params:
246 	 * col = column number.
247 	 * Returns: the description of the column.
248 	 */
249 	public FieldAttributes describeColumn(int col)
250 	{
251 		// GdaFieldAttributes* gda_data_model_describe_column (GdaDataModel *model,  gint col);
252 		auto p = gda_data_model_describe_column(gdaDataModel, col);
253 		
254 		if(p is null)
255 		{
256 			return null;
257 		}
258 		
259 		return ObjectG.getDObject!(FieldAttributes)(cast(GdaFieldAttributes*) p);
260 	}
261 	
262 	/**
263 	 * Params:
264 	 * col = column number.
265 	 * Returns: the title for the given column in a data model object.
266 	 */
267 	public string getColumnTitle(int col)
268 	{
269 		// const gchar* gda_data_model_get_column_title (GdaDataModel *model,  gint col);
270 		return Str.toString(gda_data_model_get_column_title(gdaDataModel, col));
271 	}
272 	
273 	/**
274 	 * Sets the title of the given col in model.
275 	 * Params:
276 	 * col = column number
277 	 * title = title for the given column.
278 	 */
279 	public void setColumnTitle(int col, string title)
280 	{
281 		// void gda_data_model_set_column_title (GdaDataModel *model,  gint col,  const gchar *title);
282 		gda_data_model_set_column_title(gdaDataModel, col, Str.toStringz(title));
283 	}
284 	
285 	/**
286 	 * Gets the position of a column on the data model, based on
287 	 * the column's title.
288 	 * Params:
289 	 * title = column title.
290 	 * Returns: the position of the column in the data model, or -1 if the column could not be found.
291 	 */
292 	public int getColumnPosition(string title)
293 	{
294 		// gint gda_data_model_get_column_position (GdaDataModel *model,  const gchar *title);
295 		return gda_data_model_get_column_position(gdaDataModel, Str.toStringz(title));
296 	}
297 	
298 	/**
299 	 * Retrieves a given row from a data model.
300 	 * Params:
301 	 * row = row number.
302 	 * Returns: a GdaRow object.
303 	 */
304 	public Row getRow(int row)
305 	{
306 		// const GdaRow* gda_data_model_get_row (GdaDataModel *model,  gint row);
307 		auto p = gda_data_model_get_row(gdaDataModel, row);
308 		
309 		if(p is null)
310 		{
311 			return null;
312 		}
313 		
314 		return ObjectG.getDObject!(Row)(cast(GdaRow*) p);
315 	}
316 	
317 	/**
318 	 * Retrieves the data stored in the given position (identified by
319 	 * the col and row parameters) on a data model.
320 	 * This is the main function for accessing data in a model.
321 	 * Params:
322 	 * col = column number.
323 	 * row = row number.
324 	 * Returns: a GdaValue containing the value stored in the given position, or NULL on error (out-of-bound position, etc).
325 	 */
326 	public Value getValueAt(int col, int row)
327 	{
328 		// const GdaValue* gda_data_model_get_value_at (GdaDataModel *model,  gint col,  gint row);
329 		auto p = gda_data_model_get_value_at(gdaDataModel, col, row);
330 		
331 		if(p is null)
332 		{
333 			return null;
334 		}
335 		
336 		return ObjectG.getDObject!(Value)(cast(GdaValue*) p);
337 	}
338 	
339 	/**
340 	 * Checks whether the given data model can be updated or not.
341 	 * Returns: TRUE if it can be updated, FALSE if not.
342 	 */
343 	public int isUpdatable()
344 	{
345 		// gboolean gda_data_model_is_updatable (GdaDataModel *model);
346 		return gda_data_model_is_updatable(gdaDataModel);
347 	}
348 	
349 	/**
350 	 * Appends a row to the given data model.
351 	 * Params:
352 	 * values = GList of GdaValue* representing the row to add. The
353 	 *  length must match model's column count. These GdaValue
354 	 *  are value-copied. The user is still responsible for freeing them.
355 	 * Returns: the added row.
356 	 */
357 	public Row appendRow(ListG values)
358 	{
359 		// const GdaRow* gda_data_model_append_row (GdaDataModel *model,  const GList *values);
360 		auto p = gda_data_model_append_row(gdaDataModel, (values is null) ? null : values.getListGStruct());
361 		
362 		if(p is null)
363 		{
364 			return null;
365 		}
366 		
367 		return ObjectG.getDObject!(Row)(cast(GdaRow*) p);
368 	}
369 	
370 	/**
371 	 * Removes a row from the data model. This results in the underlying
372 	 * database row being removed in the database.
373 	 * Params:
374 	 * row = the GdaRow to be removed.
375 	 * Returns: TRUE if successful, FALSE otherwise.
376 	 */
377 	public int removeRow(Row row)
378 	{
379 		// gboolean gda_data_model_remove_row (GdaDataModel *model,  const GdaRow *row);
380 		return gda_data_model_remove_row(gdaDataModel, (row is null) ? null : row.getRowStruct());
381 	}
382 	
383 	/**
384 	 * Updates a row data model. This results in the underlying
385 	 * database row's values being changed.
386 	 * Params:
387 	 * row = the GdaRow to be updated.
388 	 * Returns: TRUE if successful, FALSE otherwise.
389 	 */
390 	public int updateRow(Row row)
391 	{
392 		// gboolean gda_data_model_update_row (GdaDataModel *model,  const GdaRow *row);
393 		return gda_data_model_update_row(gdaDataModel, (row is null) ? null : row.getRowStruct());
394 	}
395 	
396 	/**
397 	 * Appends a column to the given data model. If successful, the position of
398 	 * the new column in the data model is set on col, and you can grab it using
399 	 * gda_field_attributes_get_position.
400 	 * Params:
401 	 * attrs = a GdaFieldAttributes describing the column to add.
402 	 * Returns: TRUE if successful, FALSE otherwise.
403 	 */
404 	public int appendColumn(FieldAttributes attrs)
405 	{
406 		// gboolean gda_data_model_append_column (GdaDataModel *model,  const GdaFieldAttributes *attrs);
407 		return gda_data_model_append_column(gdaDataModel, (attrs is null) ? null : attrs.getFieldAttributesStruct());
408 	}
409 	
410 	/**
411 	 * Updates a column in the given data model. This results in the underlying
412 	 * database row's values being changed.
413 	 * Params:
414 	 * col = the column to be updated.
415 	 * attrs = attributes for the column.
416 	 * Returns: TRUE if successful, FALSE otherwise.
417 	 */
418 	public int updateColumn(int col, FieldAttributes attrs)
419 	{
420 		// gboolean gda_data_model_update_column (GdaDataModel *model,  gint col,  const GdaFieldAttributes *attrs);
421 		return gda_data_model_update_column(gdaDataModel, col, (attrs is null) ? null : attrs.getFieldAttributesStruct());
422 	}
423 	
424 	/**
425 	 * Removes a column from the data model. This means that all values attached to this
426 	 * column in the data model will be destroyed in the underlying database.
427 	 * Params:
428 	 * col = the column to be removed.
429 	 * Returns: TRUE if successful, FALSE otherwise.
430 	 */
431 	public int removeColumn(int col)
432 	{
433 		// gboolean gda_data_model_remove_column (GdaDataModel *model,  gint col);
434 		return gda_data_model_remove_column(gdaDataModel, col);
435 	}
436 	
437 	/**
438 	 * Calls the specified callback function for each row in the data model.
439 	 * This will just traverse all rows, and call the given callback
440 	 * function for each of them.
441 	 * Params:
442 	 * func = callback function.
443 	 * userData = context data for the callback function.
444 	 */
445 	public void foreac(GdaDataModelForeachFunc func, void* userData)
446 	{
447 		// void gda_data_model_foreach (GdaDataModel *model,  GdaDataModelForeachFunc func,  gpointer user_data);
448 		gda_data_model_foreach(gdaDataModel, func, userData);
449 	}
450 	
451 	/**
452 	 * Checks whether this data model is in updating mode or not. Updating
453 	 * mode is set to TRUE when gda_data_model_begin_update has been
454 	 * called successfully, and is not set back to FALSE until either
455 	 * gda_data_model_cancel_update or gda_data_model_end_update have
456 	 * been called.
457 	 * Returns: TRUE if updating mode, FALSE otherwise.
458 	 */
459 	public int hasChanged()
460 	{
461 		// gboolean gda_data_model_has_changed (GdaDataModel *model);
462 		return gda_data_model_has_changed(gdaDataModel);
463 	}
464 	
465 	/**
466 	 * Starts update of this data model. This function should be the
467 	 * first called when modifying the data model.
468 	 * Returns: TRUE on success, FALSE if there was an error.
469 	 */
470 	public int beginUpdate()
471 	{
472 		// gboolean gda_data_model_begin_update (GdaDataModel *model);
473 		return gda_data_model_begin_update(gdaDataModel);
474 	}
475 	
476 	/**
477 	 * Cancels update of this data model. This means that all changes
478 	 * will be discarded, and the old data put back in the model.
479 	 * Returns: TRUE on success, FALSE if there was an error.
480 	 */
481 	public int cancelUpdate()
482 	{
483 		// gboolean gda_data_model_cancel_update (GdaDataModel *model);
484 		return gda_data_model_cancel_update(gdaDataModel);
485 	}
486 	
487 	/**
488 	 * Approves all modifications and send them to the underlying
489 	 * data source/store.
490 	 * Returns: TRUE on success, FALSE if there was an error.
491 	 */
492 	public int endUpdate()
493 	{
494 		// gboolean gda_data_model_end_update (GdaDataModel *model);
495 		return gda_data_model_end_update(gdaDataModel);
496 	}
497 	
498 	/**
499 	 * Converts the given model into a comma-separated series of rows.
500 	 * Returns: the representation of the model. You should free this string when you no longer need it.
501 	 */
502 	public string toCommaSeparated()
503 	{
504 		// gchar* gda_data_model_to_comma_separated (GdaDataModel *model);
505 		return Str.toString(gda_data_model_to_comma_separated(gdaDataModel));
506 	}
507 	
508 	/**
509 	 * Converts the given model into a tab-separated series of rows.
510 	 * Returns: the representation of the model. You should free this string when you no longer need it.
511 	 */
512 	public string toTabSeparated()
513 	{
514 		// gchar* gda_data_model_to_tab_separated (GdaDataModel *model);
515 		return Str.toString(gda_data_model_to_tab_separated(gdaDataModel));
516 	}
517 	
518 	/**
519 	 * Converts the given model into a XML representation.
520 	 * Params:
521 	 * standalone = whether ...
522 	 * Returns: the representation of the model. You should free this string when you no longer need it.
523 	 */
524 	public string toXml(int standalone)
525 	{
526 		// gchar* gda_data_model_to_xml (GdaDataModel *model,  gboolean standalone);
527 		return Str.toString(gda_data_model_to_xml(gdaDataModel, standalone));
528 	}
529 	
530 	/**
531 	 * Converts a GdaDataModel into a xmlNodePtr (as used in libxml).
532 	 * Params:
533 	 * name = name to use for the XML resulting table.
534 	 * Returns: a xmlNodePtr representing the whole data model.
535 	 */
536 	public xmlNodePtr toXmlNode(string name)
537 	{
538 		// xmlNodePtr gda_data_model_to_xml_node (GdaDataModel *model,  const gchar *name);
539 		return gda_data_model_to_xml_node(gdaDataModel, Str.toStringz(name));
540 	}
541 	
542 	/**
543 	 * Adds the data from a XML node to the given data model.
544 	 * Params:
545 	 * node = a XML node representing a lt;datagt; XML node.
546 	 * Returns: TRUE if successful, FALSE otherwise.
547 	 */
548 	public int addDataFromXmlNode(xmlNodePtr node)
549 	{
550 		// gboolean gda_data_model_add_data_from_xml_node  (GdaDataModel *model,  xmlNodePtr node);
551 		return gda_data_model_add_data_from_xml_node(gdaDataModel, node);
552 	}
553 	
554 	/**
555 	 * Gets the text of command that generated this data model.
556 	 * Returns: a string with the command issued.
557 	 */
558 	public string getCommandText()
559 	{
560 		// const gchar* gda_data_model_get_command_text (GdaDataModel *model);
561 		return Str.toString(gda_data_model_get_command_text(gdaDataModel));
562 	}
563 	
564 	/**
565 	 * Sets the command text of the given model.
566 	 * Params:
567 	 * txt = the command text.
568 	 */
569 	public void setCommandText(string txt)
570 	{
571 		// void gda_data_model_set_command_text (GdaDataModel *model,  const gchar *txt);
572 		gda_data_model_set_command_text(gdaDataModel, Str.toStringz(txt));
573 	}
574 	
575 	/**
576 	 * Gets the type of command that generated this data model.
577 	 * Returns: a GdaCommandType.
578 	 */
579 	public GdaCommandType getCommandType()
580 	{
581 		// GdaCommandType gda_data_model_get_command_type (GdaDataModel *model);
582 		return gda_data_model_get_command_type(gdaDataModel);
583 	}
584 	
585 	/**
586 	 * Sets the type of command that generated this data model.
587 	 * Params:
588 	 * type = the type of the command (one of GdaCommandType)
589 	 */
590 	public void setCommandType(GdaCommandType type)
591 	{
592 		// void gda_data_model_set_command_type (GdaDataModel *model,  GdaCommandType type);
593 		gda_data_model_set_command_type(gdaDataModel, type);
594 	}
595 }