18 #ifndef DBMODELPRIVATE_H
19 #define DBMODELPRIVATE_H
26 #include <QAbstractTableModel>
29 #include <dbmodel/dbmodel-config.h>
30 #include <dbmodel/dbmodelcol.h>
31 #include <dbmodel/dbmodeltbl.h>
32 #include <dbstruct/dbstruct.h>
33 #include <dbstruct/dbtaew.h>
43 # define DBMODEL_DEBUGM printf
45 # define DBMODEL_DEBUGM black_hole
49 # define DBMODEL_TRACE_ENTRY printf("DBMODEL ENTRY %s in %s[%d]\n", __func__, __FILE__, __LINE__)
51 # define DBMODEL_TRACE_ENTRY
55 # define DBMODEL_TRACE_EXIT printf("DBMODEL EXIT %s in %s[%d]\n", __func__, __FILE__, __LINE__)
57 # define DBMODEL_TRACE_EXIT
61 # define TMP_A(__s__) __s__.toLatin1 ().constData ()
64 static inline void black_hole (...)
101 QList<DbModelCol> mapping_;
103 QList<DbModelTbl> tables_;
141 return (db_ != NULL) &&
142 (tables_.count() > 0) &&
143 tables_.at (0).isValid();
163 if (tables_.count() == 0)
165 DbTaew * result = tables_.first().metadata();
166 tables_.first().setMetadata (NULL);
176 if (tables_.count() == 0)
178 return tables_.at (0).metadata();
182 inline QSqlTableModel *
184 if (tables_.count() == 0)
186 return tables_.at (0).sqlModel ();
217 DbStruct * result = db_;
230 return mapping_.at (index);
236 int table_index)
const {
238 return tables_.at (table_index);
244 const QString & filter,
245 int table_index = 0);
250 const QString & filter,
251 const QString & table);
258 int table_index = 0);
265 const QString & table);
270 const QString & table)
const;
292 const QModelIndex &index)
const;
296 const QModelIndex &idx,
297 int role = Qt::DisplayRole)
const;
302 Qt::Orientation orientation,
303 int role = Qt::DisplayRole)
const;
308 Qt::Orientation orientation,
309 const QVariant & value,
310 int role = Qt::EditRole);
314 const QModelIndex &index,
315 const QVariant &value,
316 int role = Qt::EditRole);
321 const QModelIndex &idx)
const;
327 Qt::SortOrder order = Qt::AscendingOrder) {
335 const DbColumn &colorig,
336 const QVariant &original_value);
343 const QModelIndex &parent);
350 const QModelIndex &parent)
const;
354 const QModelIndex &parent)
const;
387 return row_highlite_;
393 return col_highlite_;
399 return (col_highlite_ > -1) && (row_highlite_ > -1);
410 DbColumn::Callback value,
419 columnCallbackData() {
437 const QString &name);
445 addForeignKeyColumn (
446 const DbColumn & col,
465 #endif // DBMODELPRIVATE_H
bool selectMe()
Select the model (retreive information using options).
Definition: dbmodelprivate.cc:191
int columnCount() const
Number of columns.
Definition: dbmodelprivate.cc:252
const DbModelTbl & tableData(int table_index) const
Get the model data regarding a table.
Definition: dbmodelprivate.h:235
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Set sorting order.
Definition: dbmodelprivate.h:325
Internal model.
Definition: dbmodelprivate.h:75
A Qt model capable of representing sql tables.
Definition: dbmodel.h:26
DbModelPrivate(DbStruct *db, DbTaew *meta, DbModel *parent)
Create a new model from a table or view definition and a database.
Definition: dbmodelprivate.cc:73
bool isValid() const
Is this a valid model (with a table set) or not?
Definition: dbmodelprivate.h:140
int rowCount() const
Number of rows.
Definition: dbmodelprivate.cc:237
QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const
Definition: dbmodelprivate.cc:717
static QVariant formattedData(const DbColumn &colorig, const QVariant &original_value)
Convert the data for the user.
Definition: dbmodelprivate.cc:499
bool removeRows(int row, int count, const QModelIndex &parent)
Remove a number of rows.
Definition: dbmodelprivate.cc:701
bool validateIndex(const QModelIndex &idx) const
Tell if an index is valid for this model.
Definition: dbmodelprivate.cc:973
DbTaew * metaTaew() const
Get a pointer to meta object; ownership stays with this instance.
Definition: dbmodelprivate.h:175
Model representation of a column.
Definition: dbmodelcol.h:56
int findTable(const QString &table) const
Find the index of a model identified by its name.
Definition: dbmodelprivate.cc:430
bool setFilter(const QString &filter, int table_index=0)
Set a filter on one of the internal models identified by its index.
Definition: dbmodelprivate.cc:284
void reloadHeaders()
Read the labels again (possibly in a different language).
Definition: dbmodelprivate.cc:1196
bool hasMarkerCell() const
Tell if we have a highlite cell set.
Definition: dbmodelprivate.h:398
void setMeta(DbTaew *meta)
Definition: dbmodelprivate.cc:148
DbTaew * takeMeta()
Give away the pointer and remove it from internal storage.
Definition: dbmodelprivate.h:162
file dbmodeltbl.h date November 2015 author Nicu Tofan
Definition: dbmodeltbl.h:46
bool setCurrentMarker(int row, int column)
Set the indicated cell.
Definition: dbmodelprivate.cc:1220
QSqlRecord record(int row) const
Get a record for a row.
Definition: dbmodelprivate.cc:1186
bool setColumnCallback(int table_index, int column_index, DbColumn::Callback value, void *user_data)
Definition: dbmodelprivate.cc:1254
const DbModelCol & columnData(int index) const
Get the model data regarding a column; index is a real index.
Definition: dbmodelprivate.h:227
virtual ~DbModelPrivate()
destructor
Definition: dbmodelprivate.cc:118
DbStruct * takeDatabase()
Give away the pointer and remove it from internal storage.
Definition: dbmodelprivate.h:216
bool setOrder(int column, Qt::SortOrder order, int table_index=0)
Set a filter on one of the internal models identified by its index.
Definition: dbmodelprivate.cc:350
void setDatabase(DbStruct *value)
Set the database; also invalidates the table.
Definition: dbmodelprivate.cc:265
DbStruct * database() const
Definition: dbmodelprivate.h:204
int getMarkerCol() const
Retreive highlite column.
Definition: dbmodelprivate.h:392
DbModel * parentDbModel() const
Get the front-end model.
Definition: dbmodelprivate.cc:128
QSqlTableModel * mainModel() const
Get a pointer to internal main model object.
Definition: dbmodelprivate.h:183
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
Definition: dbmodelprivate.cc:955
int getMarkerRow() const
Retreive highlite row.
Definition: dbmodelprivate.h:386