完成画线
This commit is contained in:
1 parent
faa315e904
commit
cc54d43b0c
6 files changed
+42
-15
No files matched your search
@@ -61,7 +61,7 @@ void ParkingSpaceWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setPen(Qt::black);
|
||||
// painter.drawText(20, 25, QString::number(number));
|
||||
painter.drawText(20, 25, QString::number(number));
|
||||
QString p;
|
||||
p.append(QString::number(pos().x()));
|
||||
p.append(",");
|
||||
@@ -69,7 +69,7 @@ void ParkingSpaceWidget::paintEvent(QPaintEvent *)
|
||||
|
||||
painter.setPen(Qt::white);
|
||||
painter.setBrush(Qt::white);
|
||||
painter.save();
|
||||
//painter.save();
|
||||
painter.translate(30, 20);
|
||||
switch (dir) {
|
||||
case E:
|
||||
@@ -92,9 +92,9 @@ void ParkingSpaceWidget::paintEvent(QPaintEvent *)
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);*/
|
||||
|
||||
painter.restore();
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawText(0, 25, p);
|
||||
//painter.restore();
|
||||
//painter.setPen(Qt::black);
|
||||
//painter.drawText(0, 25, p);
|
||||
painter.end();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,9 +44,9 @@ void Road::paintEvent(QPaintEvent * event)
|
||||
y += 50;
|
||||
}
|
||||
}
|
||||
painter.setPen(Qt::red);
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.drawRect(0, 0, width() - 1, height() - 1);
|
||||
//painter.setPen(Qt::red);
|
||||
//painter.setBrush(Qt::NoBrush);
|
||||
//painter.drawRect(0, 0, width() - 1, height() - 1);
|
||||
}
|
||||
|
||||
Road::~Road()
|
||||
|
||||
@@ -31,7 +31,3 @@ Monitor::~Monitor()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ void ParkingLotManager::drawPath(uint n1, uint n2)
|
||||
{
|
||||
Path *p = m_graph[1]->finaPath(ParkingLotGraph::Node::Type::space, n1,
|
||||
ParkingLotGraph::Node::Type::space, n2);
|
||||
for(uint i = 1; i < p->size(); i++) {
|
||||
for(int i = 1; i < p->pointsCount(); i++) {
|
||||
QLineF line(p->getPoint(i-1).point, p->getPoint(i).point);
|
||||
m_scene->addLine(line);
|
||||
}
|
||||
|
||||
+31
-1
@@ -23,7 +23,7 @@ QPoint toCenter(const QWidget* w) {
|
||||
return p;
|
||||
}
|
||||
|
||||
ParkingLotGraph::ParkingLotGraph(const ParkingLotWidget* pk)
|
||||
ParkingLotGraph::ParkingLotGraph(const ParkingLotWidget* pkl): pk(pkl)
|
||||
{
|
||||
QVector<ParkingSpaceWidget*> spaces = pk->getSpaceList();
|
||||
QVector<Road*> roads = pk->getRoadList();
|
||||
@@ -197,8 +197,38 @@ Path *ParkingLotGraph::finaPath(ParkingLotGraph::Node::Type t1, uint n1, Parking
|
||||
uint n = id2;
|
||||
while (n != id1) {
|
||||
path->addPoint(0, *(new PathPoint(QPointF(m_all[n]->data), 0)));
|
||||
QPoint tp;
|
||||
if (m_all[n]->type == Node::Type::space) {
|
||||
ParkingSpaceWidget* space = pk->getSpaceList().at(m_all[n]->number - 1);
|
||||
switch (space->getDir()) {
|
||||
case ParkingSpaceWidget::direction::E:
|
||||
case ParkingSpaceWidget::direction::W:
|
||||
tp.setX(m_all[prev[n]]->data.x());
|
||||
tp.setY(m_all[n]->data.y());
|
||||
break;
|
||||
case ParkingSpaceWidget::direction::N:
|
||||
case ParkingSpaceWidget::direction::S:
|
||||
tp.setX(m_all[n]->data.x());
|
||||
tp.setY(m_all[prev[n]]->data.y());
|
||||
break;
|
||||
}
|
||||
} else if (m_all[n]->type == Node::Type::road) {
|
||||
Road* road = pk->getRoadList().at(m_all[n]->number - 1);
|
||||
switch(road->getDir()) {
|
||||
case Road::direction::horizontal:
|
||||
tp.setX(m_all[prev[n]]->data.x());
|
||||
tp.setY(m_all[n]->data.y());
|
||||
break;
|
||||
case Road::direction::vertical:
|
||||
tp.setX(m_all[n]->data.x());
|
||||
tp.setY(m_all[prev[n]]->data.y());
|
||||
break;
|
||||
}
|
||||
}
|
||||
path->addPoint(0, PathPoint(QPointF(tp), 0));
|
||||
n = prev[n];
|
||||
}
|
||||
path->addPoint(0, PathPoint(QPointF(m_all[n]->data), 0)); // 把第一个点也加进去
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -24,7 +24,7 @@ public:
|
||||
QVector<float> weight;
|
||||
uint getId() const;
|
||||
};
|
||||
ParkingLotGraph(const ParkingLotWidget*);
|
||||
ParkingLotGraph(const ParkingLotWidget*pkl);
|
||||
Node* addNode(QPoint p, Node::Type t, uint n) {
|
||||
Node* no = new Node(p, t, n, m_all.size());
|
||||
m_all.push_back(no);
|
||||
@@ -37,6 +37,7 @@ private:
|
||||
QVector<Node* > m_all;
|
||||
QVector<Node* > m_spaceList;
|
||||
QVector<Node* > m_roadNodeList;
|
||||
const ParkingLotWidget* pk;
|
||||
};
|
||||
|
||||
#endif // PARKINGLOTGRAPH_H
|
||||
Reference in new issue
Block a user