diff --git a/sea_transport/sea_transport.pro b/sea_transport/sea_transport.pro index be07897..bf9d0a6 100644 --- a/sea_transport/sea_transport.pro +++ b/sea_transport/sea_transport.pro @@ -25,6 +25,7 @@ SOURCES += \ system/object_system.cpp \ usereditdialog.cpp \ vesseleditdialog.cpp \ + viewmodels/deliverypointsviewmodel.cpp \ viewmodels/usersviewmodel.cpp \ viewmodels/vesselsviewmodel.cpp @@ -46,6 +47,7 @@ HEADERS += \ system/object_system.h \ usereditdialog.h \ vesseleditdialog.h \ + viewmodels/deliverypointsviewmodel.h \ viewmodels/usersviewmodel.h \ viewmodels/vesselsviewmodel.h diff --git a/sea_transport/viewmodels/deliverypointsviewmodel.cpp b/sea_transport/viewmodels/deliverypointsviewmodel.cpp new file mode 100644 index 0000000..5823d9c --- /dev/null +++ b/sea_transport/viewmodels/deliverypointsviewmodel.cpp @@ -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()); +} diff --git a/sea_transport/viewmodels/deliverypointsviewmodel.h b/sea_transport/viewmodels/deliverypointsviewmodel.h new file mode 100644 index 0000000..bfbfb40 --- /dev/null +++ b/sea_transport/viewmodels/deliverypointsviewmodel.h @@ -0,0 +1,22 @@ +#ifndef DELIVERYPOINTSVIEWMODEL_H +#define DELIVERYPOINTSVIEWMODEL_H + +#include "system/apparatus.h" + +#include + +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