Add and implemented Delivery Point VM

This commit is contained in:
Andrew nuark G 2020-12-22 22:40:40 +07:00
parent 2f67449c72
commit 6231e7efb0
3 changed files with 83 additions and 0 deletions

View file

@ -0,0 +1,59 @@
#include "deliverypointsviewmodel.h"
DeliveryPointsViewModel::DeliveryPointsViewModel(QObject *parent) : QAbstractTableModel(parent) {
}
int DeliveryPointsViewModel::rowCount(const QModelIndex &/*parent*/) const {
return apparatus::instance()->get_object_subsystem()->dpoints().length();
}
int DeliveryPointsViewModel::columnCount(const QModelIndex &/*parent*/) const {
return 4;
}
QVariant DeliveryPointsViewModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch (section) {
case 0:
return QString("DPID");
case 1:
return QString("Title");
case 2:
return QString("Storages count");
case 3:
return QString("Storages total volume");
}
}
return QVariant();
}
QVariant DeliveryPointsViewModel::data(const QModelIndex &index, int role) const {
if (role == Qt::DisplayRole) {
auto item = apparatus::instance()->get_object_subsystem()->dpoints()[index.row()];
int col = index.column();
switch (col) {
case 0:
return QString::number(item.id());
case 1:
return item.title();
case 2:
return item.storages().length();
case 3:
int tvol = 0;
foreach (auto storage, item.storages()) {
tvol += storage.capacity();
}
return tvol;
}
return "UNKNOWN FIELD";
}
return QVariant();
}
void DeliveryPointsViewModel::update() {
dataChanged(QModelIndex(), QModelIndex());
}

View file

@ -0,0 +1,22 @@
#ifndef DELIVERYPOINTSVIEWMODEL_H
#define DELIVERYPOINTSVIEWMODEL_H
#include "system/apparatus.h"
#include <QAbstractTableModel>
class DeliveryPointsViewModel : public QAbstractTableModel {
Q_OBJECT
public:
DeliveryPointsViewModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
public slots:
void update();
};
#endif // DELIVERYPOINTSVIEWMODEL_H