libgdamm: Gnome::Gda::DataModel Class Reference
Abstract DataModel (Base class for all DataModels). More...
Public Types | |
typedef std::vector< Value > | ValueVector |
Public Types inherited from sigc::trackable | |
typedef internal::func_destroy_notify | func_destroy_notify |
Public Member Functions | |
DataModel (DataModel&& src) noexcept | |
DataModel& | operator= (DataModel&& src) noexcept |
virtual | ~DataModel () noexcept |
GdaDataModel* | gobj () |
Provides access to the underlying C GObject. More... | |
const GdaDataModel* | gobj () const |
Provides access to the underlying C GObject. More... | |
void | freeze () |
Disables notifications of changes on the given data model. More... | |
void | thaw () |
Re-enables notifications of changes on the given data model. More... | |
int | get_n_rows () const |
int | get_n_columns () const |
int | get_column_index (const Glib::ustring& name) |
Get the index of the first column named name in model. More... | |
Glib::RefPtr< Column > | describe_column (int col) |
Queries the underlying data model implementation for a description of a given column. More... | |
Glib::RefPtr< const Column > | describe_column (int col) const |
Queries the underlying data model implementation for a description of a given column. More... | |
Glib::ustring | get_column_title (int col) const |
void | set_column_title (int col, const Glib::ustring& title) |
Sets the title of the given col in model. More... | |
Value | get_value_at (int col, int row) const |
Retrieves the data stored in the given position (identified by the col and row parameters) on a data model. More... | |
Value | get_typed_value_at (int col, int row, GType expected_type, bool nullok) const |
Upon errors 0 will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain. More... | |
ValueAttribute | get_attributes_at (int col, int row) |
Get the attributes of the value stored at (row, col) in model, which is an ORed value of Gda::ValueAttribute flags. More... | |
Glib::RefPtr< DataModelIter > | create_iter () |
Creates a new iterator object Gda::DataModelIter object which can be used to iterate through rows in model. More... | |
bool | set_value_at (int col, int row, const Value& value) |
Modifies a value in model, at ( col, row). More... | |
bool | set_values (int row, const std::vector< Value >& values) |
In a similar way to set_value_at(), this method modifies a data model's contents by setting several values at once. More... | |
DataModelAccessFlags | get_access_flags () const |
Get the attributes of model such as how to access the data it contains if it's modifiable, etc. More... | |
int | append_values (const std::vector< Value >& values) |
Appends a row to the given data model. More... | |
bool | append_row () |
Appends a row to the data model (the new row will possibly have 0 values for all columns, or some other values depending on the data model implementation) More... | |
bool | remove_row (int row) |
Removes a row from the data model. More... | |
int | get_row_from_values (const ValueVector& values, const std::vector< int >& cols_index) |
Returns the first row where all the values in values at the columns identified at cols_index match. More... | |
void | send_hint (DataModelHint hint, const Value& hint_value) |
Sends a hint to the data model. More... | |
Glib::ustring | export_to_string (DataModelIOFormat format, const std::vector< int >& cols, const std::vector< int >& rows, const Glib::RefPtr< Set >& options) |
Exports data contained in model to the a string; the format is specified using the format argument. More... | |
bool | export_to_file (DataModelIOFormat format, const std::string& file, const std::vector< int >& cols, const std::vector< int >& rows, const Glib::RefPtr< Set >& options) |
Exports data contained in model to the file; the format is specified using the format argument. More... | |
bool | import_from_model (const Glib::RefPtr< DataModel >& from, bool overwrite, GHashTable* cols_trans) |
Copy the contents of the from data model to the to data model. More... | |
bool | import_from_string (const Glib::ustring&string, GHashTable* cols_trans, const Glib::RefPtr< const Set >& options) |
Loads the data from string into model. More... | |
bool | import_from_file (const std::string& file, GHashTable* cols_trans, const Glib::RefPtr< const Set >& options) |
Imports data contained in the file file into model; the format is detected. More... | |
void | dump (FILE* to_stream) const |
Dumps a textual representation of the model to the to_stream stream. More... | |
Glib::ustring | dump_as_string () const |
Dumps a textual representation of the model into a new string. More... | |
void | set_column_name (int col, const Glib::ustring& name) |
Sets the name of the given col in model, and if its title is not set, also sets the title to name. More... | |
Glib::ustring | get_column_name (int col) const |
bool | iter_move_next_default (const Glib::RefPtr< DataModelIter >& iter) |
bool | iter_move_prev_default (const Glib::RefPtr< DataModelIter >& iter) |
bool | iter_move_to_row_default (const Glib::RefPtr< DataModelIter >& iter, int row) |
Glib::SignalProxy1< void, int > | signal_row_inserted () |
Glib::SignalProxy1< void, int > | signal_row_updated () |
Glib::SignalProxy1< void, int > | signal_row_removed () |
Glib::SignalProxy0< void > | signal_reset () |
Glib::SignalProxy0< void > | signal_changed () |
Public Member Functions inherited from Glib::Interface | |
Interface () | |
Interface (Interface &&src) noexcept | |
Interface & | operator= (Interface &&src) noexcept |
Interface (const Glib::Interface_Class &interface_class) | |
Interface (GObject *castitem) | |
virtual | ~Interface () noexcept |
Interface (const Interface &)=delete | |
Interface & | operator= (const Interface &)=delete |
GObject * | gobj () |
const GObject * | gobj () const |
Public Member Functions inherited from Glib::ObjectBase | |
ObjectBase (const ObjectBase &)=delete | |
ObjectBase & | operator= (const ObjectBase &)=delete |
void | set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value) |
void | get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const |
void | set_property (const Glib::ustring &property_name, const PropertyType &value) |
void | get_property (const Glib::ustring &property_name, PropertyType &value) const |
void | connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void > &slot) |
sigc::connection | connect_property_changed_with_return (const Glib::ustring &property_name, const sigc::slot< void > &slot) |
void | freeze_notify () |
void | thaw_notify () |
virtual void | reference () const |
virtual void | unreference () const |
GObject * | gobj () |
const GObject * | gobj () const |
GObject * | gobj_copy () const |
Public Member Functions inherited from sigc::trackable | |
trackable () | |
trackable (const trackable &src) | |
trackable (trackable &&src) noexcept | |
~trackable () | |
void | add_destroy_notify_callback (void *data, func_destroy_notify func) const |
void | notify_callbacks () |
trackable & | operator= (const trackable &src) |
trackable & | operator= (trackable &&src) noexcept |
void | remove_destroy_notify_callback (void *data) const |
Static Public Member Functions | |
static void | add_interface (GType gtype_implementer) |
static GType | get_type () |
Get the GType for this class, for use with the underlying GObject type system. More... | |
Protected Member Functions | |
DataModel () | |
You should derive from this class to use it. More... | |
virtual void | on_row_inserted (int row) |
This is a default handler for the signal signal_row_inserted(). More... | |
virtual void | on_row_updated (int row) |
This is a default handler for the signal signal_row_updated(). More... | |
virtual void | on_row_removed (int row) |
This is a default handler for the signal signal_row_removed(). More... | |
virtual void | on_reset () |
This is a default handler for the signal signal_reset(). More... | |
virtual void | on_changed () |
This is a default handler for the signal signal_changed(). More... | |
Protected Member Functions inherited from Glib::ObjectBase | |
ObjectBase () | |
ObjectBase (const char *custom_type_name) | |
ObjectBase (const std::type_info &custom_type_info) | |
ObjectBase (ObjectBase &&src) noexcept | |
ObjectBase & | operator= (ObjectBase &&src) noexcept |
virtual | ~ObjectBase () noexcept=0 |
void | initialize (GObject *castitem) |
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper) |
Related Functions | |
(Note that these are not member functions.) | |
Glib::RefPtr< Gnome::Gda::DataModel > | wrap (GdaDataModel* object, bool take_copy=false) |
A Glib::wrap() method for this object. More... | |
Detailed Description
Abstract DataModel (Base class for all DataModels).
A DataModel represents an array of values organized in rows and columns. All the data in the same column have the same type, and all the data in each row have the same semantic meaning. The DataModel is actually an interface implemented by other objects to support various kinds of data storage and operations.
Depending on the real implementation, the contents of data models may be modified by the user by using functions provided by the model. The actual operations that a data model permits can be discovered using the get_access_flags() method.
Again, depending on the real implementation, data retreival can be done either by accessing direct random values located by their row and column, or by using a DataModelIter cursor, or both. Use the get_access_flags() method to discover how the data model can be accessed. Note that a Datamodel which can be accessed in a random way can also be accessed using cursors (and several cusrors may be used at the same time), whereas a data model which can only be accessed using cursors can only have one cursor for iterating.
Random access data models are easier to use since picking a value is very simple by using the get_value_at(), but they consume more memory since all the accessible values must generally be present in memory even if they are not used. Thus, if a data model must handle large quantities of data, it is generally wiser to use a data model which can be only accessed using a cursor.
As a side note there are also data models which wrap other data models such as:
- The DataProxy data model which stores temporary modifications and shows only some parts of the wrapped data model.
- The DataAccessWrapper data model which offers memory-efficient random access on top of a wrapped cursor based access data model.
Member Typedef Documentation
Constructor & Destructor Documentation
|
protected |
You should derive from this class to use it.
|
noexcept |
|
virtualnoexcept |
Member Function Documentation
|
static |
bool Gnome::Gda::DataModel::append_row | ( | ) |
Appends a row to the data model (the new row will possibly have 0
values for all columns, or some other values depending on the data model implementation)
Upon errors -1 will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
- Returns
- The number of the added row, or -1 if an error occurred.
int Gnome::Gda::DataModel::append_values | ( | const std::vector< Value >& | values | ) |
Appends a row to the given data model.
If any value in values is actually 0
, then it is considered as a default value.
Upon errors -1 will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
- Parameters
-
values List of Value* representing the row to add. The length must match model's column count. These Value are value-copied (the user is still responsible for freeing them).
- Returns
- The number of the added row, or -1 if an error occurred.
Glib::RefPtr<DataModelIter> Gnome::Gda::DataModel::create_iter | ( | ) |
Creates a new iterator object Gda::DataModelIter object which can be used to iterate through rows in model.
Depending on the data model's implementation, a new Gda::DataModelIter object may be created, or a reference to an already existing Gda::DataModelIter may be returned.
If a new Gda::DataModelIter is created, then the row it represents is undefined.
For models which can be accessed randomly, any row can be set using Gda::DataModelIter::move_to_row(), and for models which are accessible sequentially only then use Gda::DataModelIter::move_next() (and Gda::DataModelIter::move_prev() if supported).
- Returns
- A Gda::DataModelIter object, or
0
if an error occurred.
Glib::RefPtr<Column> Gnome::Gda::DataModel::describe_column | ( | int | col | ) |
Queries the underlying data model implementation for a description of a given column.
That description is returned in the form of a Gda::Column structure, which contains all the information about the given column in the data model.
WARNING: the returned Gda::Column object belongs to the model model and and should not be destroyed; any modification will affect the whole data model.
- Parameters
-
col Column number.
- Returns
- The description of the column.
Glib::RefPtr<const Column> Gnome::Gda::DataModel::describe_column | ( | int | col | ) | const |
Queries the underlying data model implementation for a description of a given column.
That description is returned in the form of a Gda::Column structure, which contains all the information about the given column in the data model.
WARNING: the returned Gda::Column object belongs to the model model and and should not be destroyed; any modification will affect the whole data model.
- Parameters
-
col Column number.
- Returns
- The description of the column.
void Gnome::Gda::DataModel::dump | ( | FILE * | to_stream | ) | const |
Dumps a textual representation of the model to the to_stream stream.
The following environment variables can affect the resulting output:
- GDA_DATA_MODEL_DUMP_ROW_NUMBERS: if set, the first column of the output will contain row numbers
- GDA_DATA_MODEL_DUMP_ATTRIBUTES: if set, also dump the data model's columns' types and value's attributes
- GDA_DATA_MODEL_DUMP_TITLE: if set, also dump the data model's title
- GDA_DATA_MODEL_DUMP_NULL_AS_EMPTY: if set, replace the '
0
' string with an empty string for0
values
- Parameters
-
to_stream Where to dump the data model.
Glib::ustring Gnome::Gda::DataModel::dump_as_string | ( | ) | const |
Dumps a textual representation of the model into a new string.
The following environment variables can affect the resulting output:
- GDA_DATA_MODEL_DUMP_ROW_NUMBERS: if set, the first column of the output will contain row numbers
- GDA_DATA_MODEL_DUMP_TITLE: if set, also dump the data model's title
- GDA_DATA_MODEL_DUMP_NULL_AS_EMPTY: if set, replace the '
0
' string with an empty string for0
values
- Returns
- A new string.
bool Gnome::Gda::DataModel::export_to_file | ( | DataModelIOFormat | format, |
const std::string & | file, | ||
const std::vector< int > & | cols, | ||
const std::vector< int > & | rows, | ||
const Glib::RefPtr< Set >& | options | ||
) |
Exports data contained in model to the file; the format is specified using the format argument.
Specifically, the parameters in the list can be:
- SEPARATOR: a string value of which the first character is used as a separator in case of CSV export. -"NAME: a string value used to name the exported data if the export format is XML.
- OVERWRITE: a boolean value which tells if the file must be over-written if it already exists.
- Parameters
-
format The format in which to export data. file The filename to export to. cols An array containing which columns of will be exported. rows An array containing which rows of will be exported. options List of options for the export.
- Returns
- true if no error occurred.
Glib::ustring Gnome::Gda::DataModel::export_to_string | ( | DataModelIOFormat | format, |
const std::vector< int > & | cols, | ||
const std::vector< int > & | rows, | ||
const Glib::RefPtr< Set >& | options | ||
) |
Exports data contained in model to the a string; the format is specified using the format argument.
Specifically, the parameters in the list can be:
- SEPARATOR: a string value of which the first character is used as a separator in case of CSV export. -"NAME: a string value used to name the exported data if the export format is XML.
- OVERWRITE: a boolean value which tells if the file must be over-written if it already exists.
- Parameters
-
format The format in which to export data. cols An array containing which columns of will be exported. rows An array containing which rows of will be exported. options List of options for the export.
- Returns
- The string.
void Gnome::Gda::DataModel::freeze | ( | ) |
Disables notifications of changes on the given data model.
To re-enable notifications again, you should call the #gda_data_model_thaw function.
DataModelAccessFlags Gnome::Gda::DataModel::get_access_flags | ( | ) | const |
Get the attributes of model such as how to access the data it contains if it's modifiable, etc.
- Returns
- An ORed value of Gda::DataModelAccessFlags flags.
ValueAttribute Gnome::Gda::DataModel::get_attributes_at | ( | int | col, |
int | row | ||
) |
Get the attributes of the value stored at (row, col) in model, which is an ORed value of Gda::ValueAttribute flags.
As a special case, if row is -1, then the attributes returned correspond to a "would be" value if a row was added to model.
- Parameters
-
col A valid column number. row A valid row number, or -1.
- Returns
- The attributes as an ORed value of Gda::ValueAttribute.
int Gnome::Gda::DataModel::get_column_index | ( | const Glib::ustring & | name | ) |
Get the index of the first column named name in model.
- Parameters
-
name A column name.
- Returns
- The column index, or -1 if no column named name was found.
Glib::ustring Gnome::Gda::DataModel::get_column_name | ( | int | col | ) | const |
- Parameters
-
col Column number.
- Returns
- The name for the given column in a data model object.
Glib::ustring Gnome::Gda::DataModel::get_column_title | ( | int | col | ) | const |
- Parameters
-
col Column number.
- Returns
- The title for the given column in a data model object.
int Gnome::Gda::DataModel::get_n_columns | ( | ) | const |
- Returns
- The number of columns in the given data model.
int Gnome::Gda::DataModel::get_n_rows | ( | ) | const |
- Returns
- The number of rows in the given data model, or -1 if the number of rows is not known.
int Gnome::Gda::DataModel::get_row_from_values | ( | const ValueVector& | values, |
const std::vector< int > & | cols_index | ||
) |
Returns the first row where all the values in values at the columns identified at cols_index match.
If the row can't be identified, then returns -1;
NOTE: the cols_index array MUST contain a column index for each value in values
- Parameters
-
values A list of Value values (no 0
is allowed).cols_index An array of int
containing the column number to match each value of values.
- Returns
- The requested row number, of -1 if not found.
|
static |
Get the GType for this class, for use with the underlying GObject type system.
Value Gnome::Gda::DataModel::get_typed_value_at | ( | int | col, |
int | row, | ||
GType | expected_type, | ||
bool | nullok | ||
) | const |
Upon errors 0
will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
This method is similar to get_value_at(), except that it also allows one to specify the expected Type of the value to get: if the data model returned a Value of a type different than the expected one, then this method returns 0
and an error code.
- Note
- the same limitations and usage instructions apply as for get_value_at().
Upon errors false
will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
- Parameters
-
col A valid column number. row A valid row number. expected_type The expected data type of the returned value. nullok If true
, then0
values (value of type Gda::TYPE_NULL) will not generate any error.
- Returns
- A Value containing the value stored in the given position, or
0
on error (out-of-bound position, wrong data type, etc).
Value Gnome::Gda::DataModel::get_value_at | ( | int | col, |
int | row | ||
) | const |
Retrieves the data stored in the given position (identified by the col and row parameters) on a data model.
Upon errors 0
will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
This is the main function for accessing data in a model which allows random access to its data. To access data in a data model using a cursor, use a Gda::DataModelIter object, obtained using create_iter().
- Note
- the returned Value must not be modified directly (unexpected behaviours may occur if you do so).
- the returned value may become invalid as soon as any Libgda part is executed again, which means if you want to keep the value, a copy must be made, however it will remain valid as long as the only Libgda usage is calling get_value_at() for different values of the same row.
If you want to modify a value stored in a Gda::DataModel, use the set_value_at() or set_values() methods.
Upon errors 0
will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
- Parameters
-
col A valid column number. row A valid row number.
- Returns
- A Value containing the value stored in the given position, or
0
on error (out-of-bound position, etc).
|
inline |
Provides access to the underlying C GObject.
|
inline |
Provides access to the underlying C GObject.
bool Gnome::Gda::DataModel::import_from_file | ( | const std::string & | file, |
GHashTable * | cols_trans, | ||
const Glib::RefPtr< const Set >& | options | ||
) |
Imports data contained in the file file into model; the format is detected.
Upon errors false
will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
- Parameters
-
file The filename to import from. cols_trans A HashTable for columns translating, or 0
, see import_from_model().options List of options for the export.
- Returns
true
if no error occurred.
bool Gnome::Gda::DataModel::import_from_model | ( | const Glib::RefPtr< DataModel >& | from, |
bool | overwrite, | ||
GHashTable * | cols_trans | ||
) |
Copy the contents of the from data model to the to data model.
The copy stops as soon as an error orrurs.
The cols_trans is a hash table for which keys are to columns numbers and the values are the corresponding column numbers in the from data model. To set the values of a column in to to 0
, create an entry in the hash table with a negative value.
Upon errors false
will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
- Parameters
-
from The source Gda::DataModel. overwrite true
if to is completely overwritten by from's data, andfalse
if from's data is appended to to.cols_trans A HashTable for columns translating, or 0
.
- Returns
true
if no error occurred.
bool Gnome::Gda::DataModel::import_from_string | ( | const Glib::ustring & | string, |
GHashTable * | cols_trans, | ||
const Glib::RefPtr< const Set >& | options | ||
) |
Loads the data from string into model.
Upon errors false
will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
- Parameters
-
string The string to import data from. cols_trans A hash table containing which columns of model will be imported, or 0
for all columns, see import_from_model().options List of options for the export.
- Returns
true
if no error occurred.
bool Gnome::Gda::DataModel::iter_move_next_default | ( | const Glib::RefPtr< DataModelIter >& | iter | ) |
bool Gnome::Gda::DataModel::iter_move_prev_default | ( | const Glib::RefPtr< DataModelIter >& | iter | ) |
bool Gnome::Gda::DataModel::iter_move_to_row_default | ( | const Glib::RefPtr< DataModelIter >& | iter, |
int | row | ||
) |
|
protectedvirtual |
This is a default handler for the signal signal_changed().
|
protectedvirtual |
This is a default handler for the signal signal_reset().
|
protectedvirtual |
This is a default handler for the signal signal_row_inserted().
|
protectedvirtual |
This is a default handler for the signal signal_row_removed().
|
protectedvirtual |
This is a default handler for the signal signal_row_updated().
bool Gnome::Gda::DataModel::remove_row | ( | int | row | ) |
Removes a row from the data model.
Upon errors false
will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
- Parameters
-
row The row number to be removed.
- Returns
true
if successful,false
otherwise.
void Gnome::Gda::DataModel::send_hint | ( | DataModelHint | hint, |
const Value& | hint_value | ||
) |
Sends a hint to the data model.
The hint may or may not be handled by the data model, depending on its implementation
- Parameters
-
hint A hint to send to the model. hint_value An optional value to specify the hint, or 0
.
void Gnome::Gda::DataModel::set_column_name | ( | int | col, |
const Glib::ustring & | name | ||
) |
Sets the name of the given col in model, and if its title is not set, also sets the title to name.
- Parameters
-
col Column number. name Name for the given column.
void Gnome::Gda::DataModel::set_column_title | ( | int | col, |
const Glib::ustring & | title | ||
) |
Sets the title of the given col in model.
- Parameters
-
col Column number. title Title for the given column.
bool Gnome::Gda::DataModel::set_value_at | ( | int | col, |
int | row, | ||
const Value& | value | ||
) |
Modifies a value in model, at ( col, row).
Upon errors false
will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
- Returns
true
if the value in the data model has been updated and no error occurred.
bool Gnome::Gda::DataModel::set_values | ( | int | row, |
const std::vector< Value >& | values | ||
) |
In a similar way to set_value_at(), this method modifies a data model's contents by setting several values at once.
If any value in values is actually 0
, then the value in the corresponding column is left unchanged.
Upon errors false
will be returned and error will be assigned a Error from the Gda::DATA_MODEL_ERROR domain.
- Returns
true
if the value in the data model has been updated and no error occurred.
Glib::SignalProxy0< void > Gnome::Gda::DataModel::signal_changed | ( | ) |
- Slot Prototype:
void on_my_changed()
Glib::SignalProxy0< void > Gnome::Gda::DataModel::signal_reset | ( | ) |
- Slot Prototype:
void on_my_reset()
Glib::SignalProxy1< void,int > Gnome::Gda::DataModel::signal_row_inserted | ( | ) |
- Slot Prototype:
void on_my_row_inserted(int row)
Glib::SignalProxy1< void,int > Gnome::Gda::DataModel::signal_row_removed | ( | ) |
- Slot Prototype:
void on_my_row_removed(int row)
Glib::SignalProxy1< void,int > Gnome::Gda::DataModel::signal_row_updated | ( | ) |
- Slot Prototype:
void on_my_row_updated(int row)
void Gnome::Gda::DataModel::thaw | ( | ) |
Re-enables notifications of changes on the given data model.
Friends And Related Function Documentation
|
related |
A Glib::wrap() method for this object.
- Parameters
-
object The C instance. take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
- Returns
- A C++ instance that wraps this C instance.
The documentation for this class was generated from the following file:
- libgdamm/datamodel.h