From d0b6d6377de44484568af2ef3a3bbd4da7cdfb4b Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 30 Dec 2020 17:23:15 +0800 Subject: import(life): ... --- works/life/cpp-practicum/Record.hpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'works/life/cpp-practicum/Record.hpp') diff --git a/works/life/cpp-practicum/Record.hpp b/works/life/cpp-practicum/Record.hpp index e39e626..78b70ba 100644 --- a/works/life/cpp-practicum/Record.hpp +++ b/works/life/cpp-practicum/Record.hpp @@ -4,13 +4,14 @@ #include "Book.hpp" #include "Vendor.hpp" +#include #include #include #include class Record final { public: - Record(); + Record() = default; CRU_DEFAULT_COPY(Record); CRU_DEFAULT_MOVE(Record); @@ -21,16 +22,32 @@ public: void WriteTo(QFile file); void ReadFrom(QFile file); - const std::vector &GetBooks() const { return books_; } - const std::vector &GetVendors() const { return vendors_; } - - // TODO: Implementation - std::optional FindBookByIsbn(std::u16string_view isbn); - - // TODO: Implementation - void RemoveBookByIsbn(std::u16string_view isbn); + std::vector &GetBooks() { return books_; } + std::vector &GetVendors() { return vendors_; } private: std::vector books_; std::vector vendors_; }; + +class BookModel : public QAbstractTableModel { +public: + explicit BookModel(Record *record) : record_(record) {} + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const override; + QVariant data(const QModelIndex &index, + int role = Qt::DisplayRole) const override; + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole) override; + Qt::ItemFlags flags(const QModelIndex &index) const override; + bool insertRows(int row, int count, + const QModelIndex &parent = QModelIndex()) override; + bool removeRows(int row, int count, + const QModelIndex &parent = QModelIndex()) override; + +private: + Record *record_; +}; \ No newline at end of file -- cgit v1.2.3