1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#pragma once
#include "Base.hpp"
#include "Book.hpp"
#include "Vendor.hpp"
#include <QAbstractTableModel>
#include <QTextStream>
#include <optional>
#include <vector>
class Record final {
public:
Record() = default;
CRU_DEFAULT_COPY(Record);
CRU_DEFAULT_MOVE(Record);
~Record() = default;
public:
void WriteTo(QTextStream &stream);
void ReadFrom(QTextStream &stream);
std::vector<Book> &GetBooks() { return books_; }
std::vector<Vendor> &GetVendors() { return vendors_; }
private:
std::vector<Book> books_;
std::vector<Vendor> 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;
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
private:
Record *record_;
};
class VendorModel : public QAbstractTableModel {
public:
explicit VendorModel(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_;
};
|