GroupListWidget Pile   version 0.0.1
The pile attempts to provide a widget that is capable of presenting
groupsubmodel.h
Go to the documentation of this file.
1 
9 #ifndef GUARD_GROUPSUBMODEL_H_INCLUDE
10 #define GUARD_GROUPSUBMODEL_H_INCLUDE
11 
12 #include <grouplistwidget/grouplistwidget-config.h>
13 #include <QMap>
14 #include <QVariant>
15 #include <QString>
16 #include <QAbstractListModel>
17 
18 QT_BEGIN_NAMESPACE
19 class QAbstractItemModel;
20 QT_END_NAMESPACE
21 
22 class GroupModel;
23 
25 class GROUPLISTWIDGET_EXPORT GroupSubModel : public QAbstractListModel {
26  Q_OBJECT
27 
28  friend class GroupModel;
29  friend class GroupListWidget;
30 
31 public:
32 
35  GroupModel *model = NULL,
36  const QVariant & key = QVariant(),
37  const QString & lbl = QString());
38 
40  virtual ~GroupSubModel();
41 
43  int
44  listIndex () const;
45 
47  void
49  GroupModel * model) {
50  m_ = model;
51  }
52 
54  GroupModel *
55  parentModel () const {
56  return m_;
57  }
58 
60  void
62  int original_row) {
63  map_.append (original_row);
64  }
65 
67  void
68  insertSortedRecord (
69  int row);
70 
71 
73  virtual void
75  const QVariant & value) {
76  key_ = value;
77  }
78 
80  virtual const QVariant &
81  groupKey () const {
82  return key_;
83  }
84 
86  virtual void
88  const QString & value) {
89  s_label_ = value;
90  }
91 
93  virtual const QString &
94  label () const {
95  return s_label_;
96  }
97 
99  void
100  performSorting ();
101 
103  void
104  performUnsorting ();
105 
107  int
109  const QModelIndex &parent = QModelIndex()) const
110  {
111  return map_.count();
112  }
113 
114  QVariant
115  data (
116  const QModelIndex &index,
117  int role) const;
118 
119  QVariant
120  headerData (
121  int section,
122  Qt::Orientation orientation,
123  int role = Qt::DisplayRole) const;
124 
126  int
127  mapRowToBaseModel (
128  int row) const;
129 
131  const QList<int> &
132  mapping () const {
133  return map_;
134  }
135 
136 protected:
137 
138  void
139  signalReset ();
140 
141  void
142  setListIndex (
143  int value) {
144  list_index_ = value;
145  }
146 
148  void
149  baseModelDataChange (
150  int index_in_group,
151  const QVector<int> &roles);
152 
153 private:
154  GroupModel * m_;
155  QList<int> map_;
156  QVariant key_;
157  QString s_label_;
158  int list_index_;
159 }; // class GroupSubModel
160 
161 #endif // GUARD_GROUPSUBMODEL_H_INCLUDE
int rowCount(const QModelIndex &parent=QModelIndex()) const
Number of rows.
Definition: groupsubmodel.h:108
virtual void setGroupKey(const QVariant &value)
Sets the key for the grouping algorithm.
Definition: groupsubmodel.h:74
virtual const QString & label() const
Retreive the user visible label for this group.
Definition: groupsubmodel.h:94
A list widget that can group the items.
Definition: grouplistwidget.h:27
void setParentModel(GroupModel *model)
Sets the parent model.
Definition: groupsubmodel.h:48
const QList< int > & mapping() const
Maps rows in this model to rows in base model.
Definition: groupsubmodel.h:132
GroupModel * parentModel() const
Retreive the parent model.
Definition: groupsubmodel.h:55
A model representing a group that is used by the embedded lists.
Definition: groupsubmodel.h:25
virtual void setLabel(const QString &value)
Sets the user visible label for this group.
Definition: groupsubmodel.h:87
virtual const QVariant & groupKey() const
Retreive the key for the grouping algorithm.
Definition: groupsubmodel.h:81
void appendRecord(int original_row)
Insert a new record at the end of the list.
Definition: groupsubmodel.h:61
A model that is to be installed into a GroupListWidget.
Definition: groupmodel.h:36