Log
This commit is contained in:
1 parent
45df7c452f
commit
c0bc0c24be
7 files changed
+116
-44
No files matched your search
@@ -80,6 +80,8 @@ public:
|
||||
void requestSpace(void);
|
||||
void go(void);
|
||||
|
||||
bool requested = false;
|
||||
|
||||
private:
|
||||
Status m_status;
|
||||
Color m_color; //车身颜色 N为0, 顺时针递增
|
||||
|
||||
@@ -65,6 +65,7 @@ void LoginDialog::ok()
|
||||
f.write(psd.toStdString().c_str());
|
||||
first = false;
|
||||
}
|
||||
f.close();
|
||||
} else {
|
||||
ui->hint->setText("两次密码不匹配");
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QTime>
|
||||
#include <QCloseEvent>
|
||||
#include <QFile>
|
||||
|
||||
|
||||
LogWindow* LogWindow::m_instance = nullptr;
|
||||
@@ -18,6 +19,24 @@ LogWindow::LogWindow(QWidget *parent) :
|
||||
setGeometry(parent->x() + parent->width(), y(), 400, 450);
|
||||
this->hide();
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
connect(ui->save, &QPushButton::clicked, this, &LogWindow::save);
|
||||
connect(ui->clear, &QPushButton::clicked, this, &LogWindow::clear);
|
||||
}
|
||||
|
||||
void LogWindow::clear()
|
||||
{
|
||||
ui->text->clear();
|
||||
}
|
||||
|
||||
void LogWindow::save()
|
||||
{
|
||||
QFile f(QString("Log_%1.log").arg(QTime::currentTime().toString("hh_mm_ss")));
|
||||
if (f.open(QFile::WriteOnly| QIODevice::Text)) {
|
||||
i("保存文件");
|
||||
f.write(buffer.toStdString().c_str());
|
||||
buffer.clear();
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
|
||||
LogWindow::~LogWindow()
|
||||
@@ -35,6 +54,8 @@ LogWindow *LogWindow::newInstance(QWidget *parent)
|
||||
void LogWindow::i(QString text)
|
||||
{
|
||||
getInstance()->text->append(QTime::currentTime().toString("hh:mm:ss")+":"+text);
|
||||
getInstance()->buffer.append(QTime::currentTime().toString("hh:mm:ss")+":"+text);
|
||||
getInstance()->buffer.append("\n");
|
||||
}
|
||||
|
||||
void LogWindow::closeEvent(QCloseEvent *e)
|
||||
|
||||
@@ -26,9 +26,12 @@ signals:
|
||||
private:
|
||||
static LogWindow* m_instance;
|
||||
explicit LogWindow(QWidget *parent = 0);
|
||||
void clear(void);
|
||||
void save(void);
|
||||
|
||||
Ui::LogWindow *ui;
|
||||
QTextEdit * text;
|
||||
QString buffer;
|
||||
};
|
||||
|
||||
#endif // LOGWINDOW_H
|
||||
+53
-29
@@ -13,41 +13,65 @@
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<widget class="QWidget" name="">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>450</height>
|
||||
<width>401</width>
|
||||
<height>451</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>398</width>
|
||||
<height>448</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QTextEdit" name="text">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>450</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="clear">
|
||||
<property name="text">
|
||||
<string>清除</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="save">
|
||||
<property name="text">
|
||||
<string>保存</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>397</width>
|
||||
<height>414</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QTextEdit" name="text">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>411</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
||||
+8
-6
@@ -37,12 +37,14 @@ Monitor::Monitor(MainWindow *parent) :
|
||||
ui->sequence->hide();
|
||||
QObject::connect(ui->addCar, &QPushButton::clicked, [this, pk]() {
|
||||
QString p = this->ui->plateNumBox->text();
|
||||
if(checkPlate(p) == false) {
|
||||
QMessageBox::warning(this, "警告", "车牌不合规则");
|
||||
} else if (pk->checkSame(p)) {
|
||||
QMessageBox::warning(this, "警告", "车牌重复");
|
||||
} else {
|
||||
pk->addCar(p, ui->selectColor->currentIndex(), -1);
|
||||
if (p.size() != 0) {
|
||||
if(checkPlate(p) == false) {
|
||||
QMessageBox::warning(this, "警告", "车牌不合规则");
|
||||
} else if (pk->checkSame(p)) {
|
||||
QMessageBox::warning(this, "警告", "车牌重复");
|
||||
} else {
|
||||
pk->addCar(p, ui->selectColor->currentIndex(), -1);
|
||||
}
|
||||
}
|
||||
});
|
||||
QObject::connect(ui->random, &QPushButton::clicked, pk, &ParkingLotManager::addCarR);
|
||||
|
||||
+28
-9
@@ -238,7 +238,7 @@ void ParkingLotManager::requestOut(Car *car, int exit)
|
||||
else
|
||||
p = m_graph[car->getCurrentFloor()]->
|
||||
findPath(NODE_TYPE::space, car->getNum(), NODE_TYPE::stair, exit);
|
||||
if (m_pool.size() < m_max)
|
||||
if (GET_SITUATION(car->getCurrentFloor(), car->getNum()-1) != BANNED)
|
||||
m_pool.append(qMakePair(car->getCurrentFloor(), car->getNum() - 1));
|
||||
m_widgets[car->getCurrentFloor()]->
|
||||
getSpaceList()[car->getNum() - 1]->setSituation(ParkingSpaceWidget::free);
|
||||
@@ -281,6 +281,7 @@ void ParkingLotManager::requestBack(Car *car)
|
||||
void ParkingLotManager::requestIn(Car* car)
|
||||
{
|
||||
int entry = car->getEntryNum();
|
||||
car->requested = true;
|
||||
if (!m_pool.empty()) {
|
||||
uint l = m_pool.first().first;
|
||||
int n = m_pool.first().second + 1;
|
||||
@@ -328,13 +329,12 @@ void ParkingLotManager::leave(Car* car)
|
||||
|
||||
void ParkingLotManager::addCarR()
|
||||
{
|
||||
Log::i("生成车");
|
||||
|
||||
int entry = (rand() % m_num_of_entry);
|
||||
if (m_waitting[entry].size() > 10)
|
||||
return;
|
||||
|
||||
Car *car = new Car(this);
|
||||
Log::i(QString("生成车:").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);
|
||||
@@ -368,6 +368,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()));
|
||||
if (m_current_floor != 1)
|
||||
car->hide();
|
||||
}
|
||||
@@ -405,12 +406,13 @@ void ParkingLotManager::generatePool(bool sequence, int max)
|
||||
for (int l = m_num_of_layer - 1; l >= 0; l--) {
|
||||
for (int n = 0; n < m_capacity[l]; n++) {
|
||||
if (max-- == 0)
|
||||
return;
|
||||
goto OUT;
|
||||
if (GET_SITUATION(l, n) == FREE) {
|
||||
m_pool.append(qMakePair(l, n));
|
||||
}
|
||||
}
|
||||
}
|
||||
OUT:
|
||||
if (!sequence)
|
||||
std::random_shuffle(m_pool.begin(), m_pool.end());
|
||||
Log::i(QString("生成车位池成功,当前共有") + QString::number(m_pool.size()) + "个空车位");
|
||||
@@ -424,27 +426,44 @@ void ParkingLotManager::periodWork()
|
||||
for (auto c: m_all_cars) {
|
||||
c->leaveProbability(2);
|
||||
}
|
||||
callIn();
|
||||
}
|
||||
|
||||
void ParkingLotManager::callIn()
|
||||
{
|
||||
for (uint i = 0 ; i < m_num_of_entry; i++) {
|
||||
if (m_waitting[lastInEntry].size() == 0)
|
||||
lastInEntry = (lastInEntry + 1) % m_num_of_entry ;
|
||||
else {
|
||||
if (m_waitting[lastInEntry].size() != 0) {
|
||||
Log::i(QString("从%1召唤车").arg(lastInEntry));
|
||||
Car *c = m_waitting[lastInEntry][0];
|
||||
c->requestSpace();
|
||||
if (c->requested)
|
||||
c->requestSpace();
|
||||
}
|
||||
lastInEntry = (lastInEntry + 1) % m_num_of_entry ;
|
||||
}
|
||||
}
|
||||
|
||||
void ParkingLotManager::setMax(int max)
|
||||
{
|
||||
int n = m_max;
|
||||
int mmax = max;
|
||||
m_max = max;
|
||||
Log::i(QString("设置最大容量%1").arg(max));
|
||||
generatePool(m_sequence, max);
|
||||
for (int l = m_num_of_layer - 1; l >= 0; l--) {
|
||||
for (int n = 0; n < m_capacity[l]; n++) {
|
||||
if (max > 0) {
|
||||
if (GET_SITUATION(l, n) != OCCUPIED) {
|
||||
m_widgets.at(l)->getSpaceList().at(n)->setSituation(FREE);
|
||||
m_widgets.at(l)->getSpaceList().at(n)->update();
|
||||
}
|
||||
max--;
|
||||
}
|
||||
else {
|
||||
m_widgets.at(l)->getSpaceList().at(n)->setSituation(BANNED);
|
||||
m_widgets.at(l)->getSpaceList().at(n)->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
generatePool(m_sequence, mmax);
|
||||
if (max - n == 1)
|
||||
callIn();
|
||||
else if (max - n >= 2) {
|
||||
|
||||
Reference in new issue
Block a user