Add and implemented Delivery Point VM
This commit is contained in:
parent
2f67449c72
commit
6231e7efb0
3 changed files with 83 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
59
sea_transport/viewmodels/deliverypointsviewmodel.cpp
Normal file
59
sea_transport/viewmodels/deliverypointsviewmodel.cpp
Normal 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());
|
||||
}
|
||||
22
sea_transport/viewmodels/deliverypointsviewmodel.h
Normal file
22
sea_transport/viewmodels/deliverypointsviewmodel.h
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue