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