Qt 5.10 Book Examples
IntListModel.h
Go to the documentation of this file.
1 // ======================================================================
2 // IntListModel.h
3 // ======================================================================
4 // This file is a part of the book
5 // "Qt 5.10 Professional programming with C++"
6 // http://qt-book.com
7 // ======================================================================
8 // Copyright (c) 2017 by Max Schlee
9 // ======================================================================
10 
11 #pragma once
12 
13 #include <QAbstractListModel>
14 
15 // ======================================================================
16 class IntListModel : public QAbstractListModel {
17 Q_OBJECT
18 private:
19  QList<int> m_list;
20 
21 public:
22  IntListModel(const QList<int>& list, QObject* pobj = 0);
23 
24  QVariant data(const QModelIndex& index, int nRole) const;
25 
26  bool setData(const QModelIndex& index,
27  const QVariant& value,
28  int nRole
29  );
30 
31  int rowCount(const QModelIndex& parent = QModelIndex()) const;
32 
33  QVariant headerData(int nSection,
34  Qt::Orientation orientation,
35  int nRole = Qt::DisplayRole
36  ) const;
37 
38  Qt::ItemFlags flags(const QModelIndex &index) const;
39 
40  bool insertRows(int nRow,
41  int nCount,
42  const QModelIndex& parent = QModelIndex()
43  );
44 
45  bool removeRows(int nRow,
46  int nCount,
47  const QModelIndex& parent = QModelIndex()
48  );
49 
50 };
Qt::ItemFlags flags(const QModelIndex &index) const
bool insertRows(int nRow, int nCount, const QModelIndex &parent=QModelIndex())
bool setData(const QModelIndex &index, const QVariant &value, int nRole)
QVariant data(const QModelIndex &index, int nRole) const
IntListModel(const QList< int > &list, QObject *pobj=0)
bool removeRows(int nRow, int nCount, const QModelIndex &parent=QModelIndex())
QVariant headerData(int nSection, Qt::Orientation orientation, int nRole=Qt::DisplayRole) const
int rowCount(const QModelIndex &parent=QModelIndex()) const