1 // -*- c++ -*- 2 // Generated by gmmproc 2.46.1 -- DO NOT MODIFY! 3 #ifndef _LIBGDAMM_DATAPROXY_H 4 #define _LIBGDAMM_DATAPROXY_H 5 6 7 #include <glibmm/ustring.h> 8 #include <sigc++/sigc++.h> 9 10 // -*- C++ -*- // 11 12 /* dataproxy.h 13 * 14 * Copyright 2003 libgdamm Development Team 15 * 16 * This library is free software; you can redistribute it and/or 17 * modify it under the terms of the GNU Lesser General Public 18 * License as published by the Free Software Foundation; either 19 * version 2.1 of the License, or (at your option) any later version. 20 * 21 * This library is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 * Lesser General Public License for more details. 25 * 26 * You should have received a copy of the GNU Lesser General Public 27 * License along with this library; if not, write to the Free 28 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 29 */ 30 31 #include <glibmm/object.h> 32 #include <glibmm/object.h> 33 #include <libgdamm/datamodel.h> 34 35 36 #ifndef DOXYGEN_SHOULD_SKIP_THIS 37 typedef struct _GdaDataProxy GdaDataProxy; 38 typedef struct _GdaDataProxyClass GdaDataProxyClass; 39 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 40 41 42 #ifndef DOXYGEN_SHOULD_SKIP_THIS 43 namespace Gnome 44 { 45 46 namespace Gda 47 { class DataProxy_Class; } // namespace Gda 48 49 } // namespace Gnome 50 #endif //DOXYGEN_SHOULD_SKIP_THIS 51 52 namespace Gnome 53 { 54 55 namespace Gda 56 { 57 58 /** Proxy to hold modifications for any DataModel, providing the DataModel interface itself. 59 * This object stores modifications made to a DataModel object which is proxied until asked to make the changes 60 * inside the DataModel. It also filters the proxied data model to show only a sample (a defined number of continuous 61 * rows) of it. 62 * 63 * Specifically, for a proxied data model having nb_cols columns and nb_rows rows, the DataProxy object has the following attributes: 64 * - 2 * nb_cols columns: 65 * - The first (>= 0) nb_cols columns are the current values stored in the proxy (which correspond to the values of the proxied data model if the considered row has not been changed). The associated values are writable. 66 * - The last nb_cols columns are the values stored in the proxied data model, at column col - nb_cols. 67 * - A variable number of rows depending on the following attributes: 68 * - Whether the proxy is configured to have an empty row as the first row. 69 * - Whether the proxy only displays parts of the proxied data model. 70 * - Whether new rows have been added to the proxy. 71 * 72 * Note that unless explicitely mentioned, the columns are read-only. 73 * 74 * @ingroup DataModels 75 */ 76 77 class DataProxy 78 : public Glib::Object, 79 public DataModel 80 { 81 82 #ifndef DOXYGEN_SHOULD_SKIP_THIS 83 84 public: 85 typedef DataProxy CppObjectType; 86 typedef DataProxy_Class CppClassType; 87 typedef GdaDataProxy BaseObjectType; 88 typedef GdaDataProxyClass BaseClassType; 89 90 // noncopyable 91 DataProxy(const DataProxy&) = delete; 92 DataProxy& operator=(const DataProxy&) = delete; 93 94 private: friend class DataProxy_Class; 95 static CppClassType dataproxy_class_; 96 97 protected: 98 explicit DataProxy(const Glib::ConstructParams& construct_params); 99 explicit DataProxy(GdaDataProxy* castitem); 100 101 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 102 103 public: 104 105 DataProxy(DataProxy&& src) noexcept; 106 DataProxy& operator=(DataProxy&& src) noexcept; 107 108 virtual ~DataProxy() noexcept; 109 110 /** Get the GType for this class, for use with the underlying GObject type system. 111 */ 112 static GType get_type() G_GNUC_CONST; 113 114 #ifndef DOXYGEN_SHOULD_SKIP_THIS 115 116 117 static GType get_base_type() G_GNUC_CONST; 118 #endif 119 120 ///Provides access to the underlying C GObject. gobj()121 GdaDataProxy* gobj() { return reinterpret_cast<GdaDataProxy*>(gobject_); } 122 123 ///Provides access to the underlying C GObject. gobj()124 const GdaDataProxy* gobj() const { return reinterpret_cast<GdaDataProxy*>(gobject_); } 125 126 ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. 127 GdaDataProxy* gobj_copy(); 128 129 private: 130 131 132 protected: 133 explicit DataProxy(const Glib::RefPtr<DataModel>& model); 134 135 136 public: 137 138 static Glib::RefPtr<DataProxy> create(const Glib::RefPtr<DataModel>& model); 139 140 141 /** Fetch the Gda::DataModel which @a proxy does proxy 142 * 143 * @return The proxied data model. 144 */ 145 Glib::RefPtr<DataModel> get_proxied_model(); 146 147 /** Fetch the Gda::DataModel which @a proxy does proxy 148 * 149 * @return The proxied data model. 150 */ 151 Glib::RefPtr<const DataModel> get_proxied_model() const; 152 153 /** Get the number of columns in the proxied data model 154 * 155 * @return The number of columns, or -1 if an error occurred. 156 */ 157 int get_proxied_model_n_cols() const; 158 159 /** Get the number of rows in the proxied data model 160 * 161 * @return The number of rows, or -1 if the number of rows is not known. 162 */ 163 int get_proxied_model_n_rows() const; 164 165 /** @return <tt>true</tt> if the proxied data model is itself read-only. 166 */ 167 bool is_read_only() const; 168 169 170 /** Retrieve a whole list of values from the @a proxy data model. This function 171 * calls gda_data_proxy_get_value() 172 * for each column index specified in @a cols_index, and generates a SList on the way. 173 * 174 * @param proxy_row A proxy row. 175 * @param cols_index Array containing the columns for which the values are requested. 176 * @param n_cols Size of @a cols_index. 177 * @return A new list of values (the list must be freed, not the values), 178 * or <tt>0</tt> if an error occurred. 179 */ 180 181 ValueVector get_values(int proxy_row, const std::vector<int>& cols_index) const; 182 183 184 /** Get the attributes of the value stored at (proxy_row, col) in @a proxy, which 185 * is an ORed value of Gda::ValueAttribute flags 186 * 187 * @param proxy_row A proxy row. 188 * @param col A valid proxy column. 189 * @return The attribute. 190 */ 191 ValueAttribute get_value_attributes(int proxy_row, int col) const; 192 193 /** Alters the attributes of the value stored at (proxy_row, col) in @a proxy. the @a alter_flags 194 * can only contain the GDA_VALUE_ATTR_IS_NULL, GDA_VALUE_ATTR_IS_DEFAULT and GDA_VALUE_ATTR_IS_UNCHANGED 195 * flags (other flags are ignored). 196 * 197 * @param proxy_row A proxy row number. 198 * @param col A valid column number. 199 * @param alter_flags Flags to alter the attributes. 200 */ 201 void alter_value_attributes(int proxy_row, int col, ValueAttribute alter_flags); 202 203 204 /** Get the @a proxy's proxied model row corresponding to @a proxy_row 205 * 206 * @param proxy_row A proxy row number. 207 * @return The proxied model's row, or -1 if @a proxy row which only exists @a proxy. 208 */ 209 int get_proxied_model_row(int proxy_row) const; 210 211 // Renamed delete/undelete to erase/unerase because delete is a C++ keyword 212 213 /** Marks the row @a proxy_row to be deleted 214 * 215 * @param proxy_row A proxy row number. 216 */ 217 void erase(int proxy_row); 218 219 /** Remove the "to be deleted" mark at the row @a proxy_row, if it existed. 220 * 221 * @param proxy_row A proxy row number. 222 */ 223 void unerase(int proxy_row); 224 225 /** Tells if the row number @a proxy_row is marked to be deleted. 226 * 227 * @param proxy_row A proxy row number. 228 * @return <tt>true</tt> if the row is marked to be deleted. 229 */ 230 bool row_is_deleted(int proxy_row) const; 231 232 /** Tells if the row number @a proxy_row is a row which has been inserted in @a proxy 233 * (and is thus not in the proxied data model). 234 * 235 * @param proxy_row A proxy row number. 236 * @return <tt>true</tt> if the row is an inserted row. 237 */ 238 bool row_is_inserted(int proxy_row) const; 239 240 241 /** Resets data at the corresponding row and column. If @a proxy_row corresponds to a new row, then 242 * that new row is deleted from @a proxy. 243 * 244 * @param proxy_row The row to cancel changes. 245 * @param col The column to cancel changes, or less than 0 to cancel any change on the @a row row. 246 */ 247 void cancel_row_changes(int proxy_row, int col); 248 249 /** Commits the modified data in the proxy back into the Gda::DataModel. 250 * 251 * @param proxy_row The row number to commit. 252 * @return <tt>true</tt> if no error occurred. 253 */ 254 void apply_row_changes(int proxy_row); 255 256 /** Tells if @a proxy contains any modifications not applied to the proxied data model. 257 * 258 * @return <tt>true</tt> if there are some modifications in @a proxy. 259 */ 260 bool has_changed() const; 261 262 /** Tells if the row number @a proxy_row has changed 263 * 264 * @param proxy_row A proxy row number. 265 * @return <tt>true</tt> if the row has changed. 266 */ 267 bool row_has_changed(int proxy_row) const; 268 269 /** Get the number of rows which have been added to @a proxy and which are not part of 270 * the proxied data model. 271 * 272 * @return The number of new rows. 273 */ 274 int get_n_new_rows() const; 275 276 /** Get the number of rows which have been modified in the proxy (the sum of rows existing in 277 * the proxied data model which have been modified, and new rows). 278 * 279 * @return The number of modified rows. 280 */ 281 int get_n_modified_rows() const; 282 283 /** Sets the size of each chunk of data to display: the maximum number of rows which 284 * can be "displayed" at a time (the maximum number of rows which @a proxy pretends to have). 285 * The default value is arbitrary 300 as it is big enough to 286 * be able to display quite a lot of data, but small enough to avoid too much data 287 * displayed at the same time. 288 * 289 * @note the rows which have been added but not yet committed will always be displayed 290 * regardless of the current chunk of data, and the modified rows which are not visible 291 * when the displayed chunk of data changes are still held as modified rows. 292 * 293 * To remove the chunking of the data to display, simply pass @a sample_size the %0 value. 294 * 295 * @param sample_size The requested size of a chunk, or 0. 296 */ 297 void set_sample_size(int sample_size); 298 299 /** Get the size of each chunk of data displayed at a time. 300 * 301 * @return The chunk (or sample) size, or 0 if chunking is disabled. 302 */ 303 int get_sample_size() const; 304 305 /** Sets the number of the first row to be available in @a proxy (in reference to the proxied data model) 306 * 307 * @param sample_start The number of the first row to be displayed. 308 */ 309 void set_sample_start(int sample_start); 310 311 /** Get the number of the first row to be available in @a proxy (in reference to the proxied data model) 312 * 313 * @return The number of the first proxied model's row. 314 */ 315 int get_sample_start() const; 316 317 /** Get the number of the last row to be available in @a proxy (in reference to the proxied data model) 318 * 319 * @return The number of the last proxied model's row. 320 */ 321 int get_sample_end() const; 322 323 /** Apply all the changes stored in the proxy to the proxied data model. The changes are done row 324 * after row, and if an error 325 * occurs, then it is possible that not all the changes to all the rows have been applied. 326 * 327 * @return <tt>true</tt> if no error occurred. 328 */ 329 bool apply_all_changes(); 330 331 /** Cancel all the changes stored in the proxy (the @a proxy will be reset to its state 332 * as it was just after creation). 333 * 334 * @return <tt>true</tt> if no error occurred. 335 */ 336 bool cancel_all_changes(); 337 338 339 /** Get the total number of filtered rows in @a proxy if a filter has been applied. As new rows 340 * (rows added to the proxy and not yet added to the proxied data model) and rows to remove 341 * (rows marked for removal but not yet removed from the proxied data model) are also filtered, 342 * the returned number also contains references to new rows and rows to be removed. 343 * 344 * @return The number of filtered rows in @a proxy, or -1 if no filter has been applied. 345 */ 346 int get_filtered_n_rows(); 347 348 /** Get the current filter expression used by @a proxy. 349 * 350 * @return The current filter expression or <tt>0</tt> if no filter has been set. 351 */ 352 Glib::ustring get_filter_expr(); 353 354 /** Sets a filter among the rows presented by @a proxy. The filter is defined by a filter expression 355 * which can be any SQL valid expression using @a proxy's columns. For instance if @a proxy has the "id" and 356 * "name" columns, then a filter can be "length(name) < 5" to filter only the rows where the length of the 357 * name is strictly inferior to 5, or "id >= 1000 and id < 2000 order by name limit 50" to filter only the rows where the id 358 * is between 1000 and 2000, ordered by name and limited to 50 rows. 359 * 360 * Note about column names: real column names can be used (double quoted if necessary), but columns can also be named 361 * "_<column number>" with column numbers starting at 1. 362 * 363 * Note that any previous filter expression is replaced with the new @a filter_expr if no error occurs 364 * (if an error occurs, then any previous filter is left unchanged). 365 * 366 * @param filter_expr An SQL based expression which will filter the contents of @a proxy, or <tt>0</tt> to remove any previous filter. 367 * @return <tt>true</tt> if no error occurred. 368 */ 369 void get_filter_expr(const Glib::ustring& filter_expr); 370 371 /** Orders by the @a col column 372 * 373 * @param col The column number to order from. 374 * @return <tt>true</tt> if no error occurred. 375 */ 376 void set_ordering_column(int col); 377 378 /** Proxied data model. 379 * 380 * @return A PropertyProxy that allows you to get or set the value of the property, 381 * or receive notification when the value of the property changes. 382 */ 383 Glib::PropertyProxy< Glib::RefPtr<DataModel> > property_model() ; 384 385 /** Proxied data model. 386 * 387 * @return A PropertyProxy_ReadOnly that allows you to get the value of the property, 388 * or receive notification when the value of the property changes. 389 */ 390 Glib::PropertyProxy_ReadOnly< Glib::RefPtr<DataModel> > property_model() const; 391 392 /** Tells if a row composed of NULL values is inserted as the proxy's first row. 393 * 394 * @return A PropertyProxy that allows you to get or set the value of the property, 395 * or receive notification when the value of the property changes. 396 */ 397 Glib::PropertyProxy< bool > property_prepend_null_entry() ; 398 399 /** Tells if a row composed of NULL values is inserted as the proxy's first row. 400 * 401 * @return A PropertyProxy_ReadOnly that allows you to get the value of the property, 402 * or receive notification when the value of the property changes. 403 */ 404 Glib::PropertyProxy_ReadOnly< bool > property_prepend_null_entry() const; 405 406 /** Tells if changes to the sample of rows displayed is done in background in several steps or if it's done in one step. 407 * 408 * @return A PropertyProxy that allows you to get or set the value of the property, 409 * or receive notification when the value of the property changes. 410 */ 411 Glib::PropertyProxy< bool > property_defer_sync() ; 412 413 /** Tells if changes to the sample of rows displayed is done in background in several steps or if it's done in one step. 414 * 415 * @return A PropertyProxy_ReadOnly that allows you to get the value of the property, 416 * or receive notification when the value of the property changes. 417 */ 418 Glib::PropertyProxy_ReadOnly< bool > property_defer_sync() const; 419 420 /** Number of rows which the proxy will contain at any time, like a sliding window on the proxied data model. 421 * 422 * @return A PropertyProxy that allows you to get or set the value of the property, 423 * or receive notification when the value of the property changes. 424 */ 425 Glib::PropertyProxy< int > property_sample_size() ; 426 427 /** Number of rows which the proxy will contain at any time, like a sliding window on the proxied data model. 428 * 429 * @return A PropertyProxy_ReadOnly that allows you to get the value of the property, 430 * or receive notification when the value of the property changes. 431 */ 432 Glib::PropertyProxy_ReadOnly< int > property_sample_size() const; 433 434 435 /** 436 * @par Slot Prototype: 437 * <tt>void on_my_%row_delete_changed(int row, bool to_be_deleted)</tt> 438 * 439 */ 440 441 Glib::SignalProxy2< void,int,bool > signal_row_delete_changed(); 442 443 444 /** 445 * @par Slot Prototype: 446 * <tt>void on_my_%sample_changed(int sample_start, int sample_end)</tt> 447 * 448 */ 449 450 Glib::SignalProxy2< void,int,int > signal_sample_changed(); 451 452 453 /** 454 * @par Slot Prototype: 455 * <tt>void on_my_%sample_size_changed(int sample_size)</tt> 456 * 457 */ 458 459 Glib::SignalProxy1< void,int > signal_sample_size_changed(); 460 461 462 /** 463 * @par Slot Prototype: 464 * <tt>void on_my_%filter_changed()</tt> 465 * 466 */ 467 468 Glib::SignalProxy0< void > signal_filter_changed(); 469 470 471 /** 472 * @par Slot Prototype: 473 * <tt>Glib::Error on_my_%validate_row_changes(int row, int proxied_row)</tt> 474 * 475 */ 476 477 Glib::SignalProxy2< Glib::Error,int,int > signal_validate_row_changes(); 478 479 480 /** 481 * @par Slot Prototype: 482 * <tt>void on_my_%row_changes_applied(int row, int proxied_row)</tt> 483 * 484 */ 485 486 Glib::SignalProxy2< void,int,int > signal_row_changes_applied(); 487 488 489 public: 490 491 public: 492 //C++ methods used to invoke GTK+ virtual functions: 493 494 protected: 495 //GTK+ Virtual Functions (override these to change behaviour): 496 497 //Default Signal Handlers:: 498 /// This is a default handler for the signal signal_row_delete_changed(). 499 virtual void on_row_delete_changed(int row, bool to_be_deleted); 500 /// This is a default handler for the signal signal_sample_changed(). 501 virtual void on_sample_changed(int sample_start, int sample_end); 502 /// This is a default handler for the signal signal_sample_size_changed(). 503 virtual void on_sample_size_changed(int sample_size); 504 /// This is a default handler for the signal signal_row_changes_applied(). 505 virtual void on_row_changes_applied(int row, int proxied_row); 506 507 508 }; 509 510 } // namespace Gda 511 } // namespace Gnome 512 513 514 namespace Glib 515 { 516 /** A Glib::wrap() method for this object. 517 * 518 * @param object The C instance. 519 * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref. 520 * @result A C++ instance that wraps this C instance. 521 * 522 * @relates Gnome::Gda::DataProxy 523 */ 524 Glib::RefPtr<Gnome::Gda::DataProxy> wrap(GdaDataProxy* object, bool take_copy = false); 525 } 526 527 528 #endif /* _LIBGDAMM_DATAPROXY_H */ 529 530