Commit ce449e49 authored by Eugene Pin's avatar Eugene Pin
Browse files

Avancement du widget neighborhood (c'est pas si simple)

parent adf359a6
Pipeline #78947 passed with stages
in 17 seconds
......@@ -3,6 +3,7 @@
#include <QDialog>
#include "neighborhood.hpp"
#include "gridview.hpp"
namespace Ui {
class NeighborhoodWidget;
......@@ -13,6 +14,7 @@ class NeighborhoodWidget : public QWidget
{
Q_OBJECT
Coord currentPoint;
public:
explicit NeighborhoodWidget(QWidget *parent = nullptr);
~NeighborhoodWidget();
......@@ -20,7 +22,12 @@ public:
//! \brief Retourne le voisinage
Neighborhood* getVoisinage() const;
QPushButton* getValidateButton();
QPushButton* getValidateButton() const;
GridView& getGridView() const ;
public slots:
Neighborhood& getNeighborhood() const;
private slots:
......
......@@ -25,9 +25,9 @@ NeighborhoodWidget::NeighborhoodWidget(QWidget *parent) :
QSize size = gv.grid_size();
Coord mileu = {size.width() / 2, size.height() / 2};
currentPoint = {size.width() / 2, size.height() / 2};
Grid newGrid(gv.get_grid());
newGrid.set_cell(mileu, 2);
newGrid.set_cell(currentPoint, 2);
gv.copy_grid(newGrid);
gv.enable_toggle_mode(1, 0);
// TODO le clic sur la cellule centrale
......@@ -43,6 +43,30 @@ Neighborhood* NeighborhoodWidget::getVoisinage() const
return nullptr;
}
QPushButton* NeighborhoodWidget::getValidateButton() {
QPushButton* NeighborhoodWidget::getValidateButton() const {
return ui->validationButton;
}
GridView& NeighborhoodWidget::getGridView() const{
return *(ui->grid_view);
}
Neighborhood& NeighborhoodWidget::getNeighborhood() const
{
Neighborhood* newNeighborhood = new Neighborhood;
Grid currentGrid = ui->grid_view->get_grid();
QSize currentSizeGrid = ui->grid_view->grid_size();
int height = currentSizeGrid.height();
int width = currentSizeGrid.width();
for(int j = 0; j < height ; j++) {
for(int i = 0; i < width ; i++) {
if( currentGrid.get_state({i,j}) == 1) {
Coord newCoord = {i - currentPoint.x, j - currentPoint.y};
newNeighborhood->addNeighbor(newCoord, 1);
std::cout << "Nouveau voisin : X=" << newCoord.x << " Y=" << newCoord.y << endl;
fflush(stdout);
}
}
}
return *newNeighborhood;
}
......@@ -188,10 +188,15 @@ void UIBuilderVisitor::visit(PropertyList &list)
NeighborhoodWidget* nw = new NeighborhoodWidget;
nw->show();
QPushButton* validateButton = nw->getValidateButton();
QObject::connect(validateButton, &QPushButton::pressed, [&list] () {
QObject::connect(validateButton, &QPushButton::pressed, [&list, &nw] () {
list.clear();
Neighborhood newNeighborhood = nw->getNeighborhood();
// TODO a finir
list.push_back();
});
QObject::connect(validateButton, &QPushButton::pressed, nw, &QWidget::close );
});
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment