Cargo edit dialog and VM
This commit is contained in:
parent
05776f19f3
commit
a6c080d36b
5 changed files with 118 additions and 32 deletions
|
|
@ -1,14 +1,26 @@
|
||||||
#include "cargoeditdialog.h"
|
#include "cargoeditdialog.h"
|
||||||
#include "ui_cargoeditdialog.h"
|
#include "ui_cargoeditdialog.h"
|
||||||
|
|
||||||
CargoEditDialog::CargoEditDialog(QWidget *parent) :
|
CargoEditDialog::CargoEditDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CargoEditDialog) {
|
||||||
QDialog(parent),
|
|
||||||
ui(new Ui::CargoEditDialog)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CargoEditDialog::~CargoEditDialog()
|
CargoEditDialog::~CargoEditDialog() {
|
||||||
{
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cargo_entity* CargoEditDialog::cargo() {
|
||||||
|
return this->_cargo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CargoEditDialog::accept() {
|
||||||
|
bool emptyTitle = ui->et_title->text().trimmed().isEmpty();
|
||||||
|
if (emptyTitle) {
|
||||||
|
QMessageBox::critical(this, "Error", "Title cannot be empty");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->_cargo = new cargo_entity(ui->et_title->text().trimmed(), ui->sb_volume->value());
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,28 @@
|
||||||
#define CARGOEDITDIALOG_H
|
#define CARGOEDITDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include "entities/cargo_entity.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class CargoEditDialog;
|
class CargoEditDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CargoEditDialog : public QDialog
|
class CargoEditDialog : public QDialog {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Ui::CargoEditDialog *ui;
|
||||||
|
|
||||||
|
cargo_entity *_cargo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CargoEditDialog(QWidget *parent = nullptr);
|
explicit CargoEditDialog(QWidget *parent = nullptr);
|
||||||
~CargoEditDialog();
|
~CargoEditDialog();
|
||||||
|
|
||||||
private:
|
cargo_entity* cargo();
|
||||||
Ui::CargoEditDialog *ui;
|
|
||||||
|
public slots:
|
||||||
|
void accept() Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CARGOEDITDIALOG_H
|
#endif // CARGOEDITDIALOG_H
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>318</width>
|
<width>318</width>
|
||||||
<height>279</height>
|
<height>127</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
|
@ -19,12 +19,12 @@
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Cargo ID:</string>
|
<string>Title</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="et_cargo_id">
|
<widget class="QLineEdit" name="et_title">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -33,28 +33,17 @@
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Quantity:</string>
|
<string>Volume:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="et_quantity">
|
<widget class="QSpinBox" name="sb_volume">
|
||||||
<property name="text">
|
<property name="minimum">
|
||||||
<string/>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="maximum">
|
||||||
</item>
|
<number>500</number>
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="label_5">
|
|
||||||
<property name="text">
|
|
||||||
<string>Destination:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QPushButton" name="btn_choose_destination">
|
|
||||||
<property name="text">
|
|
||||||
<string>Choose...</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
@ -76,14 +65,14 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_discard">
|
<widget class="QPushButton" name="pb_discard">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Discard</string>
|
<string>Discard</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_save">
|
<widget class="QPushButton" name="pb_save">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save</string>
|
<string>Save</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
54
sea_transport/viewmodels/cargoviewmodel.cpp
Normal file
54
sea_transport/viewmodels/cargoviewmodel.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
#include "cargoviewmodel.h"
|
||||||
|
|
||||||
|
CargoViewModel::CargoViewModel(QObject *parent) : QAbstractTableModel(parent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int CargoViewModel::rowCount(const QModelIndex &/*parent*/) const {
|
||||||
|
return this->_data.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CargoViewModel::columnCount(const QModelIndex &/*parent*/) const {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CargoViewModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||||
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||||
|
switch (section) {
|
||||||
|
case 0:
|
||||||
|
return QString("SID");
|
||||||
|
case 1:
|
||||||
|
return QString("Title");
|
||||||
|
case 2:
|
||||||
|
return QString("Volume");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CargoViewModel::data(const QModelIndex &index, int role) const {
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
auto item = this->_data[index.row()];
|
||||||
|
|
||||||
|
int col = index.column();
|
||||||
|
switch (col) {
|
||||||
|
case 0:
|
||||||
|
return QString::number(item.id());
|
||||||
|
case 1:
|
||||||
|
return item.title();
|
||||||
|
case 2:
|
||||||
|
return item.volume();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "UNKNOWN FIELD";
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CargoViewModel::set_data(const QVector<cargo_entity> &new_data) {
|
||||||
|
this->beginResetModel();
|
||||||
|
this->_data.clear();
|
||||||
|
this->_data += new_data;
|
||||||
|
this->endResetModel();
|
||||||
|
}
|
||||||
24
sea_transport/viewmodels/cargoviewmodel.h
Normal file
24
sea_transport/viewmodels/cargoviewmodel.h
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef CARGOVIEWMODEL_H
|
||||||
|
#define CARGOVIEWMODEL_H
|
||||||
|
|
||||||
|
#include <QVector>
|
||||||
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
|
#include "entities/cargo_entity.h"
|
||||||
|
|
||||||
|
class CargoViewModel : public QAbstractTableModel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QVector<cargo_entity> _data;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CargoViewModel(QObject *parent);
|
||||||
|
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;
|
||||||
|
|
||||||
|
void set_data(const QVector<cargo_entity> &new_data);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CARGOVIEWMODEL_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue