From 9a4b71de36b9965883dbb9938aa7c07228db61e5 Mon Sep 17 00:00:00 2001 From: Andrew nuark G Date: Tue, 22 Dec 2020 22:18:05 +0700 Subject: [PATCH] Updates and Vessels viewmodel --- sea_transport/sea_transport.pro | 6 ++++-- sea_transport/viewmodels/usersviewmodel.cpp | 9 +++++---- sea_transport/viewmodels/usersviewmodel.h | 8 ++++---- sea_transport/viewmodels/vesselsviewmodel.cpp | 6 ++++++ sea_transport/viewmodels/vesselsviewmodel.h | 13 +++++++++++++ st_test/tst_st_test.cpp | 4 ++-- 6 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 sea_transport/viewmodels/vesselsviewmodel.cpp create mode 100644 sea_transport/viewmodels/vesselsviewmodel.h diff --git a/sea_transport/sea_transport.pro b/sea_transport/sea_transport.pro index e5ceb58..be07897 100644 --- a/sea_transport/sea_transport.pro +++ b/sea_transport/sea_transport.pro @@ -25,7 +25,8 @@ SOURCES += \ system/object_system.cpp \ usereditdialog.cpp \ vesseleditdialog.cpp \ - viewmodels/usersviewmodel.cpp + viewmodels/usersviewmodel.cpp \ + viewmodels/vesselsviewmodel.cpp HEADERS += \ adminpanel.h \ @@ -45,7 +46,8 @@ HEADERS += \ system/object_system.h \ usereditdialog.h \ vesseleditdialog.h \ - viewmodels/usersviewmodel.h + viewmodels/usersviewmodel.h \ + viewmodels/vesselsviewmodel.h FORMS += \ adminpanel.ui \ diff --git a/sea_transport/viewmodels/usersviewmodel.cpp b/sea_transport/viewmodels/usersviewmodel.cpp index 93785f2..ae938c2 100644 --- a/sea_transport/viewmodels/usersviewmodel.cpp +++ b/sea_transport/viewmodels/usersviewmodel.cpp @@ -4,11 +4,11 @@ UsersViewModel::UsersViewModel(QObject *parent) : QAbstractTableModel(parent) { } -int UsersViewModel::rowCount(const QModelIndex & /*parent*/) const { - return apparatus::instance()->get_object_subsystem()->vessels().size(); +int UsersViewModel::rowCount(const QModelIndex &/*parent*/) const { + return apparatus::instance()->get_auth_subsystem()->users().length(); } -int UsersViewModel::columnCount(const QModelIndex & /*parent*/) const { +int UsersViewModel::columnCount(const QModelIndex &/*parent*/) const { return 3; } @@ -61,5 +61,6 @@ QVariant UsersViewModel::data(const QModelIndex &index, int role) const { } void UsersViewModel::update() { - this->resetInternalData(); + this->beginResetModel(); + this->endResetModel(); } diff --git a/sea_transport/viewmodels/usersviewmodel.h b/sea_transport/viewmodels/usersviewmodel.h index 411981b..2eda407 100644 --- a/sea_transport/viewmodels/usersviewmodel.h +++ b/sea_transport/viewmodels/usersviewmodel.h @@ -10,10 +10,10 @@ class UsersViewModel : public QAbstractTableModel Q_OBJECT public: UsersViewModel(QObject *parent = nullptr); - 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) const override; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + 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(); diff --git a/sea_transport/viewmodels/vesselsviewmodel.cpp b/sea_transport/viewmodels/vesselsviewmodel.cpp new file mode 100644 index 0000000..63d7454 --- /dev/null +++ b/sea_transport/viewmodels/vesselsviewmodel.cpp @@ -0,0 +1,6 @@ +#include "vesselsviewmodel.h" + +VesselsViewModel::VesselsViewModel() +{ + +} diff --git a/sea_transport/viewmodels/vesselsviewmodel.h b/sea_transport/viewmodels/vesselsviewmodel.h new file mode 100644 index 0000000..06cfd75 --- /dev/null +++ b/sea_transport/viewmodels/vesselsviewmodel.h @@ -0,0 +1,13 @@ +#ifndef VESSELSVIEWMODEL_H +#define VESSELSVIEWMODEL_H + +#include + +class VesselsViewModel : public QAbstractTableModel +{ + Q_OBJECT +public: + VesselsViewModel(); +}; + +#endif // VESSELSVIEWMODEL_H diff --git a/st_test/tst_st_test.cpp b/st_test/tst_st_test.cpp index 0e015bb..6cfc350 100644 --- a/st_test/tst_st_test.cpp +++ b/st_test/tst_st_test.cpp @@ -165,7 +165,7 @@ void st_test::vessel_entity_serialization_test() { stream.setDevice(&f); dpoint_entity test_harbor("test_harbor_for_vessel"); - ent1 = vessel_entity(test_harbor, 256); + ent1 = vessel_entity(test_harbor.id(), 256); ent1.serialize(stream); stream.setDevice(nullptr); @@ -181,7 +181,7 @@ void st_test::vessel_entity_serialization_test() { } QVERIFY2( - ent1.id() == ent2.id() && ent1.harbor().id() == ent2.harbor().id() && ent1.capacity() == ent2.capacity(), + ent1.id() == ent2.id() && ent1.harbor() == ent2.harbor() && ent1.capacity() == ent2.capacity(), "Delivery Point entity not serialized properly" ); }