Out of bounds warning
This commit is contained in:
parent
8d757e96be
commit
10ddcc51a2
3 changed files with 50 additions and 6 deletions
|
|
@ -286,3 +286,24 @@ const PointProbe GridPreview::probePoint(const QPoint &point)
|
||||||
}
|
}
|
||||||
return PointProbe();
|
return PointProbe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QList<PointProbe> GridPreview::pointsOutOfBounds()
|
||||||
|
{
|
||||||
|
QList<PointProbe> out;
|
||||||
|
|
||||||
|
for (auto iter = lines.begin(); iter != lines.end(); iter++)
|
||||||
|
{
|
||||||
|
const QPoint &start = iter->getStart();
|
||||||
|
const QPoint &end = iter->getEnd();
|
||||||
|
|
||||||
|
PointProbe startProbe = probePoint(start);
|
||||||
|
PointProbe endProbe = probePoint(end);
|
||||||
|
|
||||||
|
if (!startProbe.inBounds)
|
||||||
|
out.push_back(startProbe);
|
||||||
|
if (!endProbe.inBounds)
|
||||||
|
out.push_back(startProbe);
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ struct PointProbe
|
||||||
inBounds(bounds) {}
|
inBounds(bounds) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GridPreview : public QWidget
|
class GridPreview : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -69,6 +71,7 @@ public:
|
||||||
|
|
||||||
int getPointOwner(const QPoint& point);
|
int getPointOwner(const QPoint& point);
|
||||||
const PointProbe probePoint(const QPoint& point);
|
const PointProbe probePoint(const QPoint& point);
|
||||||
|
const QList<PointProbe> pointsOutOfBounds();
|
||||||
signals:
|
signals:
|
||||||
void updatedContents();
|
void updatedContents();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -52,18 +52,37 @@ void MainWindow::onGridUpdated()
|
||||||
{
|
{
|
||||||
if (iter->size() > 1)
|
if (iter->size() > 1)
|
||||||
{
|
{
|
||||||
QString warningTitle = QString("Color \"%1\" is used by several lines:").arg(iter.key());
|
QString title = QString("Color \"%1\" is used by several lines:").arg(iter.key());
|
||||||
QStringList warningDescription{};
|
QStringList description{};
|
||||||
|
|
||||||
for(int i = 0; i < iter->size(); i++)
|
for(int i = 0; i < iter->size(); i++)
|
||||||
{
|
{
|
||||||
warningDescription.push_back(QString("Line #%1").arg(iter->at(i)));
|
description.push_back(QString("Line #%1").arg(iter->at(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
throwWarning(warningTitle, warningDescription);
|
throwWarning(title, description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui->treeWarnings->expandAll();
|
|
||||||
|
const QList<PointProbe> outOfBounds = ui->gridPreview->pointsOutOfBounds();
|
||||||
|
|
||||||
|
for (auto iter = outOfBounds.begin(); iter != outOfBounds.end(); iter++)
|
||||||
|
{
|
||||||
|
const Line &line = ui->gridPreview->getLine(iter->ownerIndex);
|
||||||
|
const QPoint &point = iter->isStart ? line.getStart() : line.getEnd();
|
||||||
|
|
||||||
|
QString pointType = iter->isStart ? QString("Start") : QString("End");
|
||||||
|
QString title = QString("%1 point of Line #%2 is out of bounds:").arg(pointType).arg(iter->ownerIndex + 1);
|
||||||
|
QStringList description {
|
||||||
|
QString("Point located at (%1, %2) while grid size is %3x%4")
|
||||||
|
.arg(point.x())
|
||||||
|
.arg(point.y())
|
||||||
|
.arg(ui->gridPreview->getWidth())
|
||||||
|
.arg(ui->gridPreview->getHeight())
|
||||||
|
};
|
||||||
|
|
||||||
|
throwWarning(title, description);
|
||||||
|
}
|
||||||
|
|
||||||
PointProbe pp = ui->gridPreview->getCapturedProbe();
|
PointProbe pp = ui->gridPreview->getCapturedProbe();
|
||||||
|
|
||||||
|
|
@ -127,12 +146,13 @@ void MainWindow::throwWarning(const QString &title, const QStringList &descripti
|
||||||
titleItem->addChild(descriptionItem);
|
titleItem->addChild(descriptionItem);
|
||||||
}
|
}
|
||||||
ui->treeWarnings->addTopLevelItem(titleItem);
|
ui->treeWarnings->addTopLevelItem(titleItem);
|
||||||
|
ui->treeWarnings->expandItem(titleItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_buttonSave_clicked()
|
void MainWindow::on_buttonSave_clicked()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getSaveFileName(this, QString("Save grid"), ".", "Lua source code (*.lua)");
|
QString fileName = QFileDialog::getSaveFileName(this, QString("Save grid"), "level.lua", "Lua source code (*.lua)");
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue