Quark  0.1
AbstractTableModel.h++
Go to the documentation of this file.
1 
2 #ifndef __libquark_gui_AbstractTableModel_hxx
3 #define __libquark_gui_AbstractTableModel_hxx
4 
5 #include <QBuffer>
6 #include <QDebug>
7 #include <QFlags>
8 #include <QIcon>
9 #include <QMimeData>
10 #include <QStringList>
11 
13 
14 namespace quark {
15 namespace gui {
16 
39 template<class T, class IS = QDataStream, class OS = QDataStream>
41 {
42  public:
43 
45  virtual ~AbstractTableModel();
46 
48  virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
49 
51  virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
52 
54  virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole)
55  const;
56 
58  virtual bool setData(const QModelIndex &index, const QVariant &value,
59  int role = Qt::EditRole);
60 
62  virtual bool removeRows(int row, int count,
63  const QModelIndex &parent = QModelIndex());
64 
66  virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
67 
69  virtual QVariant headerData(int section, Qt::Orientation orientation,
70  int role = Qt::DisplayRole) const;
71 
73  virtual QModelIndex index(int row, int column,
74  const QModelIndex &parent = QModelIndex()) const;
75 
77  virtual QModelIndex parent(const QModelIndex &index) const;
78 
80  virtual Qt::ItemFlags flags(const QModelIndex &index) const;
81 
83  virtual QStringList mimeTypes() const;
84 
86  virtual QMimeData *mimeData(const QModelIndexList &indexes) const;
87 
89  virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action,
90  int row, int column, const QModelIndex &parent);
91 // Qt::DropActions supportedDropActions() const;
92 
94  virtual int itemCount() const = 0;
95 
100  void clear();
101 
103  bool isEmpty() const;
104 
111  void addItem(T *item);
112 
121  void insertItemAt(T *item, int row);
122 
129  T *getItemAt(int row) const;
130 
140  T *takeItemAt(int row);
141 
148  void removeItem(T *item);
149 
155  void removeItemAt(int row);
156 
165  void updateItem(T *item);
166 
174  void updateItemAt(int row);
175 
183  virtual int indexOf(const T *item) const = 0;
184 
191  bool moveItemDownAt(int row);
192 
199  bool moveItemUpAt(int row);
200 
201  int indexOfItemEqualTo(const T &item) const;
202  bool containsItemEqualTo(const T &item) const;
203 
211  virtual QString getRowName(int row) const;
212 
221  virtual QVariant getFieldValue(const T &item, int field) const = 0;
222 
223  virtual QVariant getFieldValueForRole(const T &item, int field,
224  int role) const;
225  virtual QVariant getFieldValueForRole(int field, int role) const;
226  virtual QVariant getSortValue(const T &item, int field) const;
227 
228  virtual bool write(OS &stream) const;
229  virtual bool read(IS &stream);
230 
231  protected:
232 
239  AbstractTableModel(Options options = 0, QObject *parent = NULL);
240 
242  virtual QIcon getIcon(const T &item) const;
243 
245  virtual QSize getSize(const T &item) const;
246 
248  virtual Qt::AlignmentFlag getRowHeaderAlignment() const;
249 
251  virtual void setFieldValue(T *item, int field, const QVariant &value);
252 
254  virtual void setFieldChecked(T *item, int field, bool checked);
255 
264  virtual bool isFieldEditable(const T &item, int field) const;
265 
274  virtual bool isFieldCheckable(const T &item, int field) const;
275 
277  virtual bool isFieldChecked(const T &item, int field) const;
278 
280  virtual bool isDraggable(const T &item) const;
281 
283  virtual bool isDroppable(const T &item) const;
284 
289  virtual bool isRootDroppable() const;
290 
295  virtual void itemAdded(const T *item);
296 
301  virtual void itemUpdated(const T &item);
302 
307  virtual void itemRemoved(const T &item);
308 
310  virtual T *getAt(int row) const = 0;
311 
313  virtual T *takeAt(int row) = 0;
314 
319  virtual void insertAt(T *item, int row) = 0;
320 
322  virtual void removeAll() = 0;
323 
329  virtual int getSortIndex(const T &item) const;
330 
344  virtual bool dropOtherMimeData(const QMimeData *mimeData,
345  Qt::DropAction action, int row,
346  int column, const QModelIndex &parent);
347 
352  virtual QStringList otherMimeTypes() const;
353 
355  virtual QString itemMimeType() const;
356 
364  virtual void writeProlog(OS &stream) const;
365 
374  virtual void writeItem(const T &item, OS &stream) const;
375 
383  virtual void writeEpilog(OS &stream) const;
384 
392  virtual bool readProlog(IS &stream);
393 
402  virtual T *readItem(IS &stream);
403 
411  virtual bool readEpilog(IS &stream);
412 };
413 
414 #include <quark/AbstractTableModelImpl.h++>
415 
416 } // namespace gui
417 } // namespace quark
418 
419 #endif // __libquark_gui_AbstractTableModel_hxx
void removeItem(T *item)
Removes and deletes the specified item from the model.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Specified by QAbstractItemModel.
virtual bool isDroppable(const T &item) const
Tests if a given item can be dropped onto.
virtual void itemAdded(const T *item)
Called when an item has been added to the model.
virtual QString itemMimeType() const
Returns the model&#39;s native MIME-type.
void insertItemAt(T *item, int row)
Inserts an item into the model at the given row position.
bool moveItemDownAt(int row)
Moves the given row down one position in the model.
virtual bool isFieldCheckable(const T &item, int field) const
Tests if a field of a given item is checkable.
virtual bool isFieldEditable(const T &item, int field) const
Tests if a field of a given item is editable.
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
Specified by QAbstractItemModel.
virtual T * getAt(int row) const =0
Returns the item at the given row.
virtual void setFieldChecked(T *item, int field, bool checked)
Sets the checked state of a checkable field.
void updateItem(T *item)
Notifies the model that the specified item in the model has changed in some way.
virtual void itemRemoved(const T &item)
Called when an item is about to be removed from the model.
virtual void writeEpilog(OS &stream) const
Writes any necessary epilog (e.g., an XML close-tag) when serializing items to be dragged out of the ...
virtual int getSortIndex(const T &item) const
Calculates the row at which a new item should be inserted in a presumably sorted model.
AbstractTableModel(Options options=0, QObject *parent=NULL)
Constructs an AbstractTableModel with the specified options.
virtual bool dropOtherMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Handles the dropping of MIME data with a MIME-type that is supported by (but not native to) this mode...
int indexOfItemEqualTo(const T &item) const
virtual bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Specified by QAbstractItemModel.
void updateItemAt(int row)
Notifies the model that the item in the given row has changed in some way.
virtual ~AbstractTableModel()
Destructor.
virtual void writeProlog(OS &stream) const
Writes any necessary prolog (e.g., an XML open-tag) when serializing items to be dragged out of the m...
virtual void insertAt(T *item, int row)=0
Inserts an item at the given row, or at the end if the row is negative.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Specified by QAbstractItemModel.
bool containsItemEqualTo(const T &item) const
A non-parameterized abstract base class for Quark table models.
Definition: AbstractTableModelBase.h++:20
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Specified by QAbstractItemModel.
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Specified by QAbstractItemModel.
Definition: BarChartView.h++:6
virtual bool readEpilog(IS &stream)
Reads any necessary epilog (e.g., an XML close-tag) when deserializing items that are being dropped i...
virtual bool isDraggable(const T &item) const
Tests if a given item can be dragged.
virtual QString getRowName(int row) const
Returns the name of the given row.
virtual bool isFieldChecked(const T &item, int field) const
Tests if a field of a given item is currently checked.
bool moveItemUpAt(int row)
Moves the given row up one position in the model.
An abstract base class for table data models, i.e., models in which every row represents an instance ...
Definition: AbstractTableModel.h++:40
virtual void itemUpdated(const T &item)
Called when an item has been updated in the model.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Specified by QAbstractItemModel.
virtual void writeItem(const T &item, OS &stream) const
Serializes an item that is being dragged out of the model.
virtual QModelIndex parent(const QModelIndex &index) const
Specified by QAbstractItemModel.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Specified by QAbstractItemModel.
virtual QSize getSize(const T &item) const
Returns the preferred display size of a given item, if any.
virtual void setFieldValue(T *item, int field, const QVariant &value)
Sets the value of an edited field.
virtual QVariant getFieldValueForRole(const T &item, int field, int role) const
void clear()
Removes all items from the model.
virtual bool read(IS &stream)
void addItem(T *item)
Adds an item to the model.
virtual bool write(OS &stream) const
virtual QStringList mimeTypes() const
Specified by QAbstractItemModel.
virtual T * readItem(IS &stream)
Deserializes an item that is being dropped into the model.
virtual QStringList otherMimeTypes() const
Returns a list of additional MIME-types that can be dropped onto the model.
virtual bool isRootDroppable() const
Tests if new item(s) can be dropped onto a non-existent rows in the model.
virtual int indexOf(const T *item) const =0
Returns the row position of the given item in the model.
void removeItemAt(int row)
Removes and deletes the item at the specified row.
T * getItemAt(int row) const
Returns the item in the specified row.
virtual QVariant getFieldValue(const T &item, int field) const =0
Returns the value of the given field of an object.
virtual T * takeAt(int row)=0
Removes and returns the item at the given row.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Specified by QAbstractItemModel.
T * takeItemAt(int row)
Removes and returns the item at the specified row.
virtual int itemCount() const =0
Returns the number of items in the model.
virtual Qt::AlignmentFlag getRowHeaderAlignment() const
Returns the preferred row (vertical) header label alignment.
virtual QVariant getSortValue(const T &item, int field) const
virtual bool readProlog(IS &stream)
Reads any necessary prolog (e.g., an XML open-tag) when deserializing items that are being dropped in...
virtual QIcon getIcon(const T &item) const
Returns the icon for a given item, if any.
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Specified by QAbstractItemModel.
bool isEmpty() const
Tests if the model is empty.
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Specified by QAbstractItemModel.
virtual void removeAll()=0
Removes all items from the model.