Book Shelf
Loading...
Searching...
No Matches
booktablemodel.h
Go to the documentation of this file.
1
10#ifndef BOOKTABLEMODEL_H
11#define BOOKTABLEMODEL_H
12
13#include <QAbstractTableModel>
14
15class Book;
16
17
22class BookTableModel : public QAbstractTableModel
23{
24public:
30 explicit BookTableModel(QObject *parent = nullptr);
31
37
44 int rowCount(const QModelIndex &parent) const override;
45
52 int columnCount(const QModelIndex &parent) const override;
53
61 QVariant data(const QModelIndex &index, int role) const override;
62
71 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
72
82 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
83
90 Qt::ItemFlags flags(const QModelIndex &index) const override;
91
97 void addBook(Book *book);
98
104 QList<Book *> getBookList() const;
105
106private:
107 QList<Book*> bookList;
109};
110
111#endif // BOOKTABLEMODEL_H
The Book class represents a book object.
Definition book.h:23
The BookTableModel class is a table model that stores a list of books.
Definition booktablemodel.h:23
int rowCount(const QModelIndex &parent) const override
Returns the number of rows in the model.
Definition booktablemodel.cpp:23
QVariant data(const QModelIndex &index, int role) const override
Returns the data stored under the given role for the item referred to by the index.
Definition booktablemodel.cpp:42
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns the item flags for the given index.
Definition booktablemodel.cpp:128
void addBook(Book *book)
Adds a book to the model.
Definition booktablemodel.cpp:140
BookTableModel(QObject *parent=nullptr)
Construct a new Book Table Model object.
Definition booktablemodel.cpp:14
int columnCount(const QModelIndex &parent) const override
Returns the number of columns in the model.
Definition booktablemodel.cpp:32
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Returns the data for the given role and section in the header with the specified orientation.
Definition booktablemodel.cpp:72
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Sets the role data for the item at index to value.
Definition booktablemodel.cpp:100
QList< Book * > getBookList() const
Returns the list of books in the model.
Definition booktablemodel.cpp:148
~BookTableModel()
Destroy the Book Table Model object.
Definition booktablemodel.cpp:18