diff --git a/car.cpp b/car.cpp index d102e45..535a5ed 100644 --- a/car.cpp +++ b/car.cpp @@ -222,21 +222,21 @@ QString Car::getFee() const { if (m_status == waiting) return "0"; - int elapsed = startTime.msecsTo(QTime::currentTime()); + double elapsed = startTime.msecsTo(QTime::currentTime()); switch (m_color) { case Color::Pink: - elapsed *= 1; + elapsed *= m_manager->getPink_price(); break; case Color::Red: - elapsed *= 2; + elapsed *= m_manager->getRed_price(); break; case Color::Yellow: - elapsed *= 3; + elapsed *= m_manager->getYellow_price(); break; default: break; } - return QString::number(elapsed / 1000); + return QString::number(elapsed / 1000, 'f', 2); } Car::Status Car::getStatus() const diff --git a/carlist.cpp b/carlist.cpp index 45d7a8b..e02604b 100644 --- a/carlist.cpp +++ b/carlist.cpp @@ -13,6 +13,7 @@ CarList::CarList(QWidget *parent) : setWindowTitle("车辆列表"); setGeometry(parent->x() + parent->width(), y() + parent->height() / 2, 400, 450); connect(ui->tableView, &QTableView::clicked, this, &CarList::mouseEvent); + hide(); } @@ -23,8 +24,14 @@ CarList::~CarList() void CarList::setAdapter(Adapter *adapter) { ui->tableView->setModel(adapter); - ui->tableView->resizeColumnsToContents(); - ui->tableView->resizeRowsToContents(); + ui->tableView->setColumnWidth(0, 80); + ui->tableView->setColumnWidth(1, 40); + ui->tableView->setColumnWidth(2, 80); + ui->tableView->setColumnWidth(3, 80); + ui->tableView->setColumnWidth(4, 70); + ui->tableView->setColumnWidth(5, 40); + // ui->tableView->resizeColumnsToContents(); + // ui->tableView->resizeRowsToContents(); m_carList = adapter->getCarList(); } @@ -55,7 +62,7 @@ void CarList::mouseEvent(const QModelIndex &index) Adapter::Adapter(QObject *parent, QList *list): QAbstractTableModel(parent), m_list(list) { - header << "车牌" << "车型" << "停放位置" << "驶入时间" << "已产生费用" << "操作"; + header << "车牌" << "车型" << "停放位置" << "驶入时间" << "费用" << "操作"; timer = new QTimer(this); QObject::connect(timer, &QTimer::timeout, this, &Adapter::update); timer->start(1000); // 每秒更新 @@ -78,7 +85,12 @@ QVariant Adapter::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { switch(index.column()) { case 0: return m_list->at(index.row())->getPlateNumber(); - case 1: return m_list->at(index.row())->getColor(); + case 1: switch (m_list->at(index.row())->getColor()) { + case Car::Color::Red: return "红"; + case Car::Color::Yellow: return "黄"; + case Car::Color::Pink: return "粉"; + default: return "其他"; + } case 2: return m_list->at(index.row())->getPosition(); case 3: if (m_list->at(index.row())->getStatus() == Car::waiting) diff --git a/carlist.h b/carlist.h index 8684264..4a83d23 100644 --- a/carlist.h +++ b/carlist.h @@ -14,6 +14,8 @@ namespace Ui { class CarList; } +class Car; + class Adapter: public QAbstractTableModel { public: explicit Adapter(QObject* parent, QList* list); diff --git a/monitor.cpp b/monitor.cpp index 69a0a71..d3bcd7f 100644 --- a/monitor.cpp +++ b/monitor.cpp @@ -8,12 +8,15 @@ #include "logwindow.h" #include "utils.h" #include +#include +#include Monitor::Monitor(MainWindow *parent) : QWidget(parent), ui(new Ui::Monitor) { ui->setupUi(this); + srand(time(0)); ui->selectColor->addItem("粉车"); ui->selectColor->addItem("红车"); ui->selectColor->addItem("黄车"); @@ -69,6 +72,12 @@ Monitor::Monitor(MainWindow *parent) : QString("%1在%2%3号").arg(this->ui->searchBox->text()) .arg(p.first).arg(p.second)); }); + QObject::connect(pk, &ParkingLotManager::requestPrice, [this, pk]() { + pk->setYellow_price(this->ui->yellow_price->value()); + pk->setRed_price(this->ui->red_price->value()); + pk->setPink_price(this->ui->pink_prive->value()); + }); + QObject::connect(pk, &ParkingLotManager::money, this, &Monitor::setMoney); } void Monitor::showEvent(QShowEvent *event) @@ -101,6 +110,17 @@ Monitor::~Monitor() delete ui; } +Ui::Monitor *Monitor::getUi() const +{ + return ui; +} + +void Monitor::setMoney(double n) +{ + money += n; + ui->money->setText(QString("今日收入%1元").arg(QString::number(money, 'f', 2))); +} + void Monitor::addCar() { diff --git a/monitor.h b/monitor.h index 244b3a7..12009aa 100644 --- a/monitor.h +++ b/monitor.h @@ -25,8 +25,12 @@ public: void closeListWindow(); ~Monitor(); + Ui::Monitor *getUi() const; + void setMoney(double n); + private: Ui::Monitor *ui; + double money = 0; void addCar(); Adapter *adapter; bool initialized = false; diff --git a/monitor.ui b/monitor.ui index 2634730..d0da597 100644 --- a/monitor.ui +++ b/monitor.ui @@ -67,7 +67,7 @@ - + QLayout::SetDefaultConstraint @@ -235,6 +235,88 @@ + + + + + + 粉车 + + + + + + + 1.000000000000000 + + + + + + + 元/秒 + + + + + + + + + + + 红车 + + + + + + + 2.000000000000000 + + + + + + + 元/秒 + + + + + + + + + + + 黄车 + + + + + + + 3.000000000000000 + + + + + + + 元/秒 + + + + + + + + + 今日收入0元 + + + diff --git a/parkingLotManager.cpp b/parkingLotManager.cpp index 4002ce8..7f44889 100644 --- a/parkingLotManager.cpp +++ b/parkingLotManager.cpp @@ -60,6 +60,9 @@ ParkingLotManager::ParkingLotManager(QObject* objectParent, QGraphicsScene* scen timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &ParkingLotManager::periodWork); + QTimer* priceTimer = new QTimer(this); + connect(priceTimer, &QTimer::timeout, this, &ParkingLotManager::requestPrice); + priceTimer->start(1000); } void ParkingLotManager::showParkingLot(uint pos) @@ -318,6 +321,7 @@ void ParkingLotManager::leave(Car* car) { int l = car->getCurrentFloor(); Log::i(QString("有车离开,已产生费用%1元,当前共有%2个空车位").arg(car->getFee()).arg(m_pool.size())); + emit money(car->getFee().toDouble()); callIn(); car->hide(); m_all_cars.removeOne(car); @@ -334,7 +338,7 @@ void ParkingLotManager::addCarR() return; Car *car = new Car(this); - Log::i(QString("生成车:").arg(car->getPlateNumber())); + Log::i(QString("生成车:%1").arg(car->getPlateNumber())); car->setEntryNum(entry + 1); m_waitting[entry].append(car); Path *p = m_graph[1]->findPath(NODE_TYPE::entry, entry + 1, NODE_TYPE::queueHead, entry + 1); @@ -351,7 +355,6 @@ void ParkingLotManager::addCarR() void ParkingLotManager::addCar(QString plate, int color, int entry) { - Log::i("生成车"); if (entry == -1) entry = (rand() % m_num_of_entry) + 1; if (m_waitting[entry - 1].size() > 10) @@ -368,7 +371,7 @@ void ParkingLotManager::addCar(QString plate, int color, int entry) car->setStatus(Car::waiting); m_all_cars.append(car); m_scene->addItem(car); - Log::i(QString("生成车:").arg(car->getPlateNumber())); + Log::i(QString("生成车:%1").arg(car->getPlateNumber())); if (m_current_floor != 1) car->hide(); } @@ -442,6 +445,36 @@ void ParkingLotManager::callIn() } } +double ParkingLotManager::getYellow_price() const +{ + return yellow_price; +} + +void ParkingLotManager::setYellow_price(double value) +{ + yellow_price = value; +} + +double ParkingLotManager::getRed_price() const +{ + return red_price; +} + +void ParkingLotManager::setRed_price(double value) +{ + red_price = value; +} + +double ParkingLotManager::getPink_price() const +{ + return pink_price; +} + +void ParkingLotManager::setPink_price(double value) +{ + pink_price = value; +} + void ParkingLotManager::setMax(int max) { int n = m_max; diff --git a/parkingLotManager.h b/parkingLotManager.h index cbd09bb..19881b7 100644 --- a/parkingLotManager.h +++ b/parkingLotManager.h @@ -39,6 +39,15 @@ public: QPair biSearch(const QString& plate); void showMode(bool enable); + double getPink_price() const; + void setPink_price(double value); + + double getRed_price() const; + void setRed_price(double value); + + double getYellow_price() const; + void setYellow_price(double value); + public slots: void requestIn(Car* car); void requestOut(Car* car, int exit = -1); @@ -81,6 +90,9 @@ private: bool m_sequence = true; QTimer *timer; + double pink_price = 1; + double red_price = 2; + double yellow_price = 3; signals: void enableUpButton(bool); @@ -89,8 +101,9 @@ signals: void setLoad(const QString&); void setLayerName(const QString&); void showMarginSignal(bool); - void carLeave(void); + void requestPrice(void); + void money(double n); }; #endif // PARKINGLOTITEM_H