BPS C++ API  2.24.4
bpstablemodel.h
Go to the documentation of this file.
1 
4 #ifndef BPSTABLEMODEL_H
5 #define BPSTABLEMODEL_H
6 
7 #include "bpsgui_global.h"
8 #include "bpstableoptions.h"
9 #include <QAbstractItemModel>
10 
11 class BpsTable;
12 class BpsTableItem;
13 
21 {
22  Q_OBJECT
24  friend class BpsTableItemPrivate;
25 
26 public:
37  BpsTableModel(BpsTable* aTable, QObject* aParent);
38 
40  virtual ~BpsTableModel();
41  virtual Qt::ItemFlags flags(const QModelIndex& aIndex) const;
42  virtual Qt::DropActions supportedDropActions() const;
43  virtual bool hasChildren(const QModelIndex& aParent = QModelIndex()) const;
44  virtual bool canFetchMore(const QModelIndex& aParent = QModelIndex()) const;
45  virtual void fetchMore(const QModelIndex& aParent = QModelIndex());
46  virtual int rowCount(const QModelIndex& aParent = QModelIndex()) const;
47  virtual int columnCount(const QModelIndex& aParent = QModelIndex()) const;
48  virtual QVariant data(const QModelIndex& aIndex, int aRole = Qt::DisplayRole) const;
49  virtual bool setData (const QModelIndex& aIndex, const QVariant& aValue, int aRole = Qt::EditRole);
50  virtual QVariant headerData(int aSection, Qt::Orientation aOrientation, int aRole) const;
51  virtual QModelIndex index(int aRow, int aColumn, const QModelIndex& aParent = QModelIndex()) const;
52  virtual QModelIndex parent(const QModelIndex &aIndex) const;
53  virtual bool removeRows(int aRow, int aCount, const QModelIndex &aParent = QModelIndex());
54  virtual QStringList mimeTypes() const;
55  virtual QMimeData* mimeData(const QModelIndexList& aIndexes) const;
56  virtual bool dropMimeData (const QMimeData* aData, Qt::DropAction aAction, int aRow, int aColumn, const QModelIndex& aParent);
58 
62  bool isReadOnly() const;
63 
70  void setReadOnly(bool aReadOnly);
71 
75  BpsTable* table() const;
76 
84  BpsTableItem* item(const QModelIndex& aIndex) const;
85 
93 
117  const QString& aMappingTable,
118  const QString& aMasterColumn,
119  const QString& aAttribColumn,
120  const QString& aAttribTable,
121  const QString& aNameColumn
122  );
123 
128 
134  QString optionsAttribTable(const QString& aMappingTable) const;
135 
141  QString optionsNameColumn(const QString& aMappingTable) const;
142 
147  void loadOptions(BpsTableItem* aItem);
148 
163  void addSlaveTable(BpsTable* aTable, const QString& aRefColumn);
164 
169 
174  BpsTable* slaveTable(const QString& aName) const;
175 
181 
186  bool isTree() const;
187 
193  void enableTree(bool aEnable);
194 
199  QVariant key(const QModelIndex& aIndex) const;
200 
206  QVariantList allKeys(const QModelIndex& aParent = QModelIndex()) const;
207 
214 
221  QModelIndex keyIndex(const QVariant& aKey) const;
222 
231  QModelIndex addItem(const QModelIndex& aParent = QModelIndex(), bool aSignal = true);
232 
239  void moveItem(const QModelIndex& aSrc, int aDstRow, const QModelIndex& aDstParent = QModelIndex());
240 
248  void deleteItem(const QModelIndex& aIndex);
249 
257  void deleteItems(const QModelIndexList& aIndexList);
258 
276  bool save(QString& aMessage, QModelIndexList& aIndexes, QString& aColumn);
277 
282  void copy(const QModelIndexList& aIndexList);
283 
288  void paste(const QModelIndex& aParent = QModelIndex());
289 
293  bool canAdd() const;
294 
298  bool canMove() const;
299 
303  bool canEdit() const;
304 
308  bool canDelete() const;
309 
313  bool canPaste() const;
314 
318  bool isModified() const;
319 
324 
329  void setKeyToolTipLabel(const QString& aLabel);
330 
331 signals:
332 
337  void modified(bool aModified);
338 
343  void unmodified(bool aUnmodified);
344 
350  void itemsAdded(const QModelIndexList& aIndexes);
351 
352 public slots:
353 
358  void refresh();
359 
364  void setEmpty();
365 
366 protected:
373  BpsTableModel(BpsTable* aTable, const QString& aRefColumn, BpsTableItem* aMasterItem);
374 
387  virtual BpsTableModel* createSlaveModel(BpsTable* aTable, const QString& aRefColumn, BpsTableItem* aMasterItem);
388 
410  virtual void insertTableItem(BpsTable* aTable, BpsTableItem* aItem);
411 
434  virtual void updateTableItem(BpsTable* aTable, BpsTableItem* aItem);
435 
451  virtual void deleteTableItem(BpsTable* aTable, BpsTableItem* aItem);
452 
461  virtual void loadTableItem(BpsTable* aTable, BpsTableItem* aItem, bool aAdditionalFields);
462 
471  virtual void loadTableOptions(BpsTable* aTable, BpsTableItem* aItem, const QString& aMappingTable);
472 
474 private:
475  void itemChanged(BpsTableItem* aItem);
476  void setModified(bool aModified);
478 };
479 
480 #endif // BPSTABLEMODEL_H
#define BPS_PRIVATE(Class)
Declare pointer to private object in a public class.
Definition: bpsglobals.h:102
Public include file for BPS GUI library macros.
#define BPSGUI_EXPORT
Declare class an import from the shared library.
Definition: bpsgui_global.h:22
Public include file for BpsTableOptions type.
Database table descriptor.
Definition: bpstable.h:19
Items used by BpsTableModel.
Definition: bpstableitem.h:18
A model for hierarchical or flat database tables.
Definition: bpstablemodel.h:21
void setReadOnly(bool aReadOnly)
Enable or disable read-only mode.
void itemsAdded(const QModelIndexList &aIndexes)
This signal is emitted after one or more new rows is/are added either by calling addItem,...
void moveItem(const QModelIndex &aSrc, int aDstRow, const QModelIndex &aDstParent=QModelIndex())
Moves the source item to the target.
void loadSlaveModels(BpsTableItem *aItem)
Load slave models of the item, in case they were not yet loaded.
QVariantList allKeys(const QModelIndex &aParent=QModelIndex()) const
Fetches all yet not fetched rows from database, and returns all record keys.
void enableTree(bool aEnable)
Enables or disables tree mode.
void deleteItem(const QModelIndex &aIndex)
Delete a single row from the model.
virtual void updateTableItem(BpsTable *aTable, BpsTableItem *aItem)
Update a existing item into the database.
void paste(const QModelIndex &aParent=QModelIndex())
Paste clipboard data into new items.
void setEmpty()
Clears the model and inhibits loading any records from database, independent from filter.
bool isTree() const
bool canPaste() const
QString optionsAttribTable(const QString &aMappingTable) const
Get the attribute table of a option mapping table.
BpsTable * slaveTable(const QString &aName) const
void unmodified(bool aUnmodified)
Emitted when the modification status of the model changes.
void copy(const QModelIndexList &aIndexList)
Copy items to clipboard.
virtual void loadTableItem(BpsTable *aTable, BpsTableItem *aItem, bool aAdditionalFields)
Overload this method to process items immediately after loading from the database.
bool canMove() const
virtual void insertTableItem(BpsTable *aTable, BpsTableItem *aItem)
Inserts a new item into the database.
bool canAdd() const
void modified(bool aModified)
Emitted when the modification status of the model changes.
QVariant key(const QModelIndex &aIndex) const
BpsTableModel(BpsTable *aTable, QObject *aParent)
Create a master table model.
QString optionsNameColumn(const QString &aMappingTable) const
Get the name column in the attributes table of a option mapping table.
void deleteItems(const QModelIndexList &aIndexList)
Delete a number of rows from the model.
void addSlaveTable(BpsTable *aTable, const QString &aRefColumn)
Add a slave table.
QStringList slaveTables() const
void loadOptions(BpsTableItem *aItem)
Load options of the record from the mapping tables, in case they were not yet loaded.
bool isModified() const
virtual void deleteTableItem(BpsTable *aTable, BpsTableItem *aItem)
Delete a existing item from the database.
BpsTable * table() const
void addOptions(const QString &aMappingTable, const QString &aMasterColumn, const QString &aAttribColumn, const QString &aAttribTable, const QString &aNameColumn)
Add a slave options definition.
bool canDelete() const
QModelIndex keyIndex(const QVariant &aKey) const
Get index from a key.
bool isReadOnly() const
QModelIndex firstIndex(const QModelIndex &aParent=QModelIndex())
Get index of first item.
BpsTableItem * item(const QModelIndex &aIndex) const
Get the table item of a certain index.
virtual BpsTableModel * createSlaveModel(BpsTable *aTable, const QString &aRefColumn, BpsTableItem *aMasterItem)
Create a slave table model.
void loadAdditionalFields(BpsTableItem *aItem)
Load additional fields of the record, in case they were not yet loaded.
bool canEdit() const
bool save(QString &aMessage, QModelIndexList &aIndexes, QString &aColumn)
Save pending changes to the datastore.
void refresh()
Refresh the model immediately.
QModelIndex addItem(const QModelIndex &aParent=QModelIndex(), bool aSignal=true)
Creates a new row in the model.
virtual void loadTableOptions(BpsTable *aTable, BpsTableItem *aItem, const QString &aMappingTable)
Overload this method to process options immediately after loading from the database.
QString keyToolTipLabel() const
BpsTableModel(BpsTable *aTable, const QString &aRefColumn, BpsTableItem *aMasterItem)
Constructor for slave table models.
QStringList optionsMappingTables() const
void setKeyToolTipLabel(const QString &aLabel)
Set label to display the record key as tool tip.
virtual bool canFetchMore(const QModelIndex &parent) const const
virtual int columnCount(const QModelIndex &parent) const const=0
virtual QVariant data(const QModelIndex &index, int role) const const=0
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
virtual void fetchMore(const QModelIndex &parent)
virtual Qt::ItemFlags flags(const QModelIndex &index) const const
virtual bool hasChildren(const QModelIndex &parent) const const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual QMimeData * mimeData(const QModelIndexList &indexes) const const
virtual QStringList mimeTypes() const const
virtual bool removeRows(int row, int count, const QModelIndex &parent)
virtual int rowCount(const QModelIndex &parent) const const=0
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual Qt::DropActions supportedDropActions() const const
QObject * parent() const const
typedef DropActions
DisplayRole
typedef ItemFlags
Orientation