class Product {public:...private: QString name_; double cost_; int amount_;}
class Delivery{public:...private: int deliveryNumber_; QDate deliveryDate_; QList<Product> deliveredProducts_;}
#ifndef DILIVERIESMODEL_H#define DILIVERIESMODEL_H#include <QAbstractItemModel>#include "Delivery.h"class DiliveriesModel : public QAbstractItemModel{ Q_OBJECTpublic: explicit DiliveriesModel(QObject *parent = 0); QModelIndex index(int row, int column, const QModelIndex &parent) const; QModelIndex parent(const QModelIndex &child) const; int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const;private: QList<Delivery> deliveries_;};#endif // DILIVERIESMODEL_H
#include "DiliveriesModel.h"DiliveriesModel::DiliveriesModel(QObject *parent) : QAbstractItemModel(parent){}QModelIndex DiliveriesModel::index(int row, int column, const QModelIndex &parent) const{ if(!hasIndex(row, column, parent)) { return QModelIndex(); } //Завернуть данные Delivery в QModelIndex() и вернуть???}QModelIndex DiliveriesModel::parent(const QModelIndex &child) const{ if (!index.isValid()) { return QModelIndex(); } //А тут ???}int DiliveriesModel::rowCount(const QModelIndex &parent) const{ if(parent == QModelIndex()) { // rootIndex return deliveries_.count(); } //Если индекс валидный, то получается он != rootIndex и соответсвует QList<Product> ??? //Какой то бред. if(parent.isValid()) { return deliveries_.at(parent.column()).deliveredProducts().count(); }}int DiliveriesModel::columnCount(const QModelIndex &parent) const{ Q_UNUSED ( parent ) return 3;}QVariant DiliveriesModel::data(const QModelIndex &index, int role) const{ //Не понимаю как тут будут обстоять дела}