Skip to content
Browse files

Qt 界面的统计数据

  • Loading branch information...
1 parent 5e4da16 commit 667f99e4ac4f2ed803e0229476a7d9fe2e1b5687 @ranxian committed
Showing with 65 additions and 2 deletions.
  1. +10 −0 Headers/qt/emulator.h
  2. +2 −1 Sources/elevator.cpp
  3. +1 −1 Sources/main.cpp
  4. +52 −0 Sources/qt/emulator.cpp
View
10 Headers/qt/emulator.h
@@ -8,6 +8,7 @@
#include <string>
#include "floor.h"
#include "elevator.h"
+#include <QLabel>
class Emulator : public QWidget
{
@@ -51,6 +52,15 @@ private slots:
void Move();
void Update();
+
+ QLabel *nEle;
+ QLabel *nPas;
+ QLabel *avWt;
+ QLabel *mxWt;
+ QLabel *avDur;
+ QLabel *mxDur;
+ QLabel *mnDur;
+ QLabel *avThr;
protected: /* Below is QWidget API */
void timerEvent(QTimerEvent*);
View
3 Sources/elevator.cpp
@@ -96,7 +96,7 @@ void Elevator::Letout() {
void Elevator::Letin(int dirCode) {
Floor* floor = &Emulator::floors[pos];
- while (floor->Get_nPassenger() && passengers.size() < capacity) {
+ while (floor->Get_nPassenger() && passengers.size() < unsigned(capacity)) {
Passenger *pass = floor->PopPassenger();
if (pass) passengers.push_back(pass);
}
@@ -120,6 +120,7 @@ void Elevator::Letin(int dirCode) {
}
int Elevator::AverThrput() {
+ if (Emulator::dual == 0) return -1;
return (throughput * 3600) / (Emulator::dual * Emulator::UNIT_TIME);
}
View
2 Sources/main.cpp
@@ -23,7 +23,7 @@ int Passenger::nCompleteDuration = 0;
int Passenger::totalDuration = 0;
/* Declaration of Emulator static member, similar to glable variable */
-int Emulator::dual;
+int Emulator::dual = 0;
int Emulator::nElevator ;
int Emulator::UNIT_TIME = 2;
int Emulator::nFloor;
View
52 Sources/qt/emulator.cpp
@@ -11,6 +11,47 @@
Emulator::Emulator(QWidget* parent) : QWidget(parent) {
START = 0;
+ QLabel* labelP;
+ labelP = new QLabel("Elevator:", this);
+ int bias = 20;
+ labelP->move(40 + bias, 530);
+ nEle = new QLabel("0 ", this);
+ nEle->move(100 + bias, 530);
+
+ labelP = new QLabel("Passenger:", this);
+ labelP->move(150 + bias, 530);
+ nPas = new QLabel("0 ", this);
+ nPas->move(220 + bias, 530);
+
+ labelP = new QLabel("Average wait:", this);
+ labelP->move(260 + bias, 530);
+ avWt = new QLabel("0 ", this);
+ avWt ->move(345 + bias, 530);
+
+ labelP = new QLabel("Max wait:", this);
+ labelP->move(405 + bias, 530);
+ mxWt = new QLabel("0 ", this);
+ mxWt->move(470 + bias, 530);
+
+ labelP = new QLabel("Average duration:", this);
+ labelP->move(40 + bias, 550);
+ avDur = new QLabel("0 ", this);
+ avDur->move(160 + bias, 550);
+
+ labelP = new QLabel("Max duration:", this);
+ labelP->move(210 + bias, 550);
+ mxDur = new QLabel("0 ", this);
+ mxDur->move(305 + bias, 550);
+
+ labelP = new QLabel("Min duration:", this);
+ labelP->move(365 + bias, 550);
+ mnDur = new QLabel("0 ", this);
+ mnDur->move(465 + bias, 550);
+
+ labelP = new QLabel("Average throughput:", this);
+ labelP->move(40 + bias, 570);
+ avThr = new QLabel("0 ", this);
+ avThr->move(bias + 180, 570);
start = new QPushButton("START", this);
start->move(700, 550);
@@ -21,6 +62,7 @@ Emulator::Emulator(QWidget* parent) : QWidget(parent) {
connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
connect(start, SIGNAL(clicked()), this, SLOT(startEmulationSlots()));
+
startTimer(200);
}
@@ -83,6 +125,15 @@ void Emulator::paintEvent(QPaintEvent *event)
QPen pen(Qt::gray, 2, Qt::DashDotLine);
painter.setPen(pen);
+
+ nEle->setText(QString::number(nElevator));
+ nPas->setText(QString::number(Passenger::Total()));
+ avWt->setText(QString::number(Passenger::AverWaitTime()));
+ avDur->setText(QString::number(Passenger::AverDuration()));
+ mxWt->setText(QString::number(Passenger::MaxWaitTime()));
+ mxDur->setText(QString::number(Passenger::MaxDuration()));
+ mnDur->setText(QString::number(Passenger::MinDuration()));
+ avThr->setText(QString::number(Elevator::AverThrput()));
for (i = 0; i < nFloor; i++) {
painter.drawLine(180, 67 + i * 50, 700, 67 + i * 50);
@@ -138,4 +189,5 @@ void Emulator::Update() {
for (iter = elevators.begin(); iter != elevators.end(); iter++) {
(*iter)->LetThemMove();
}
+ dual++;
}

0 comments on commit 667f99e

Please sign in to comment.
Something went wrong with that request. Please try again.