9 #ifndef GUARD_GROUPMODEL_H_INCLUDE
10 #define GUARD_GROUPMODEL_H_INCLUDE
12 #include <grouplistwidget/grouplistwidget-config.h>
19 class QAbstractItemModel;
25 class ModelId :
private QPair<int,Qt::ItemDataRole> {
27 ModelId () : QPair<int,Qt::ItemDataRole>(-1, Qt::UserRole) {}
28 ModelId (
int column, Qt::ItemDataRole role) : QPair<int,Qt::ItemDataRole>(column, role) {}
29 int column ()
const {
return first; }
30 void setColumn (
int value) { first = value; }
31 Qt::ItemDataRole role ()
const {
return second; }
32 void setRole (Qt::ItemDataRole value) { second = value; }
36 class GROUPLISTWIDGET_EXPORT
GroupModel :
public QObject {
41 enum { BaseColRole = Qt::UserRole + 1000 };
61 QAbstractItemModel *model = NULL,
62 QObject * parent = NULL);
70 QAbstractItemModel * model,
71 int grouping_col = -1,
73 Qt::SortOrder group_dir = Qt::AscendingOrder,
74 Qt::SortOrder sort_dir = Qt::AscendingOrder);
77 virtual QAbstractItemModel *
91 pixmapColumn ()
const;
96 Qt::ItemDataRole role);
99 virtual Qt::ItemDataRole
111 const QVariant & value) {
116 virtual const QVariant &
126 modelAboutToBeReset ();
135 static ComparisionReslt
140 const QVariant & v2);
147 const QList<int> & scols,
153 resetAllSubGroups ();
175 Q_ASSERT(additional_labels_.length () > 0);
176 return additional_labels_.at (0);
182 return additional_labels_.count ();
188 if ((idx < 0) || (idx > additional_labels_.length ())) {
191 return additional_labels_.at (idx);
199 additional_labels_.append (value);
200 resetAllSubGroups ();
206 int column, Qt::ItemDataRole role = Qt::DisplayRole) {
207 addLabel (
ModelId (column, role));
214 Q_ASSERT(additional_labels_.length () > 0);
215 additional_labels_[0] = value;
216 resetAllSubGroups ();
224 if ((idx < 0) || (idx > additional_labels_.length ())) {
227 additional_labels_[idx] = value;
228 resetAllSubGroups ();
236 Qt::ItemDataRole role = Qt::DisplayRole,
238 setLabel (
ModelId (column, role), idx);
257 return group_.column ();
263 return group_.column() != -1;
269 Qt::ItemDataRole role) {
270 group_.setRole (role);
274 virtual Qt::ItemDataRole
276 return group_.role ();
282 Qt::ItemDataRole role) {
283 group_label_role_ = role;
287 virtual Qt::ItemDataRole
289 return group_label_role_;
293 virtual Qt::SortOrder
303 value = defaultCompare;
321 return groups_.count();
326 groupingColumns ()
const;
330 groupingColumnLabels (
331 int * idx_crt)
const;
344 return setGroupingColumn (sender()->property(
"columnIndex").toInt ());
350 setGroupingColumn (-1);
356 Qt::SortOrder value) {
358 if (!supress_signals_)
359 emit groupingChanged (group_.column(), group_dir_);
365 setGroupingDirection (Qt::AscendingOrder);
371 setGroupingDirection (Qt::DescendingOrder);
382 buildNoGroupingGroup();
413 return sort_.column();
419 return sort_.column() != -1;
425 Qt::ItemDataRole role) {
426 sort_.setRole (role);
427 if (!supress_signals_)
428 emit sortingChanged (sort_.column(), sort_dir_);
432 virtual Qt::ItemDataRole
434 return sort_.role ();
439 virtual Qt::SortOrder
449 value = defaultCompare;
461 sortingColumns ()
const;
465 sortingColumnLabels (
466 int * idx_crt)
const;
478 return setSortingColumn (sender()->property (
"columnIndex").toInt ());
484 setSortingColumn (-1);
489 setSortingDirection (
490 Qt::SortOrder value);
495 setSortingDirection (Qt::AscendingOrder);
501 setSortingDirection (Qt::DescendingOrder);
529 baseModelDataChange (
530 const QModelIndex &topLeft,
531 const QModelIndex &bottomRight,
532 const QVector<int> &roles = QVector<int>());
539 QAbstractItemModel * value);
544 bool do_delete =
true);
550 int * index_in_group);
553 QAbstractItemModel * m_base_;
558 Qt::ItemDataRole group_label_role_;
559 Qt::SortOrder group_dir_;
563 Qt::SortOrder sort_dir_;
568 QList<GroupSubModel*> groups_;
569 bool supress_signals_;
571 QList<ModelId> additional_labels_;
574 #endif // GUARD_GROUPMODEL_H_INCLUDE
virtual void setGroupingFunc(Compare value)
Sets the function used to assign records to groups.
Definition: groupmodel.h:300
virtual int groupingColumn() const
Retreive the column in base model that decides grouping.
Definition: groupmodel.h:256
void setLabel(const ModelId &value)
Set the column and role for main label.
Definition: groupmodel.h:212
void addLabel(int column, Qt::ItemDataRole role=Qt::DisplayRole)
Add the column and role for a label to be presented to the user.
Definition: groupmodel.h:205
virtual Qt::SortOrder sortingDirection() const
Retreive the direction of sorting.
Definition: groupmodel.h:440
void addLabel(const ModelId &value)
Add the column and role for an additional label to be presented to the user.
Definition: groupmodel.h:197
virtual void setGroupingRole(Qt::ItemDataRole role)
Sets the role in base model that decides grouping.
Definition: groupmodel.h:268
virtual Qt::ItemDataRole groupLabelRole() const
Retreive the role in base model that provides group label.
Definition: groupmodel.h:288
virtual int groupCount() const
Get the number of groups curently defined inside this model.
Definition: groupmodel.h:320
const ModelId & label() const
Column and role for main label.
Definition: groupmodel.h:174
virtual Compare groupingFunc() const
Retreive the function used to assign records to groups.
Definition: groupmodel.h:309
virtual void setSortingRole(Qt::ItemDataRole role)
Sets the role in base model that decides sorting.
Definition: groupmodel.h:424
virtual bool setGroupingColumnByProperty()
Sets the column in base model that decides grouping by reading columnIndex property of the sender...
Definition: groupmodel.h:343
void setSortingAscending()
Sets the direction of sorting.
Definition: groupmodel.h:494
void setLabel(int column, Qt::ItemDataRole role=Qt::DisplayRole, int idx=0)
Set the column and role for a label.
Definition: groupmodel.h:234
virtual void setSortingFunc(Compare value)
Sets the function used to sort records inside groups.
Definition: groupmodel.h:446
void removeSorting()
No sorting.
Definition: groupmodel.h:483
int labelCount() const
Number of labels.
Definition: groupmodel.h:181
ModelId label(int idx) const
Column and role for a label.
Definition: groupmodel.h:187
virtual void setGroupLabelRole(Qt::ItemDataRole role)
Sets the role in base model that provides group label.
Definition: groupmodel.h:281
virtual Compare sortingFunc() const
Retreive the function used to sort records inside groups.
Definition: groupmodel.h:455
void setLabel(const ModelId &value, int idx)
Set the column and role for a label.
Definition: groupmodel.h:221
ComparisionReslt
The result of comparing two values.
Definition: groupmodel.h:44
void removeGrouping()
No grouping.
Definition: groupmodel.h:349
void setSortingDescending()
Sets the direction of sorting.
Definition: groupmodel.h:500
virtual int sortingColumn() const
Retreive the column in base model that decides sorting.
Definition: groupmodel.h:412
void setGroupingAscending()
Sets the direction of grouping.
Definition: groupmodel.h:364
void setGroupingDescending()
Sets the direction of grouping.
Definition: groupmodel.h:370
virtual Qt::ItemDataRole sortingRole() const
Retreive the role in base model that decides sorting.
Definition: groupmodel.h:433
virtual int isGrouping() const
Tell if we're grouping the records or not.
Definition: groupmodel.h:262
Groups the column and the role for a specific task.
Definition: groupmodel.h:25
virtual void setGroupingDirection(Qt::SortOrder value)
Sets the direction of grouping.
Definition: groupmodel.h:355
virtual const QVariant & userData() const
Retreive the opaque data useful for the user.
Definition: groupmodel.h:117
A model representing a group that is used by the embedded lists.
Definition: groupsubmodel.h:25
virtual Qt::ItemDataRole groupingRole() const
Retreive the role in base model that decides grouping.
Definition: groupmodel.h:275
virtual void setUserData(const QVariant &value)
Sets some opaque data useful for the user.
Definition: groupmodel.h:110
virtual Qt::SortOrder groupingDirection() const
Retreive the direction of grouping.
Definition: groupmodel.h:294
virtual int isSorting() const
Tell if we're sorting the records inside groups or not.
Definition: groupmodel.h:418
A model that is to be installed into a GroupListWidget.
Definition: groupmodel.h:36
virtual bool setSortingColumnByProperty()
Sets the column in base model that decides sorting by reading columnIndex property of the sender...
Definition: groupmodel.h:477