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

Avancement sur le widget grille. Remove mehode dans interface.cpp. Rename neighborhood.cpp.

parent db9a1d5b
Pipeline #78946 passed with stages
in 18 seconds
......@@ -70,9 +70,6 @@ private slots:
void on_customize_button_clicked();
//! \brief afficher le widget du choix des voisins
void show_neighborhood_widget(bool);
private:
//! \brief Initialiser la liste des transitions et voisinages disponibles
void init_transition_neighborhood_list();
......
......@@ -2,13 +2,14 @@
#define NEIGHBORHOODWIDGET_HPP
#include <QDialog>
#include "neighborhood.hpp"
namespace Ui {
class NeighborhoodWidget;
}
//! \brief Fenêtre de dialogue permettant de choisir les voisins d'une cellule de manière graphique.
class NeighborhoodWidget : public QDialog
class NeighborhoodWidget : public QWidget
{
Q_OBJECT
......@@ -17,10 +18,11 @@ public:
~NeighborhoodWidget();
//! \brief Retourne le voisinage
QString voisinage() const;
Neighborhood* getVoisinage() const;
protected:
void done(int r);
QPushButton* getValidateButton();
private slots:
private:
Ui::NeighborhoodWidget *ui;
......
......@@ -32,6 +32,7 @@ Fichier définissant la classe Property représentant une propriété chargable,
#include <QFile>
#include "coord.hpp"
#include "neighborhoodWidget.hpp"
struct StringProperty;
struct IntegerProperty;
......
......@@ -327,39 +327,10 @@ void MainWindow::disable_rule_customization()
void MainWindow::load_model(const QJsonObject &obj)
{
ui->rule_name->setText(obj.value("title").toString());
// TODO : load alphabet
ui->transition_list->setCurrentText(obj.value("transition_name").toString());
ui->neighborhood_list->setCurrentText(obj.value("neighborhood_name").toString());
bool alpha_initialise = false;
Alphabet alpha;
if (obj.value("alphabet").isArray())
{
for (auto entry : obj.value("alphabet").toArray())
{
if (!entry.isObject())
continue;
auto entry_obj = entry.toObject();
std::string name = entry_obj.value("name").toString().toStdString();
if (!entry_obj.value("color").isArray())
continue;
auto color_array = entry_obj.value("color").toArray();
stateColor color(color_array[0].toInt(), color_array[1].toInt(), color_array[2].toInt());
// Initialisation avec le premier élement
if (!alpha_initialise)
{
alpha = Alphabet(state(color, name));
alpha_initialise = true;
}
else
alpha.newEtat(state(color, name));
}
}
update_transition_settings();
update_neighborhood_settings();
disable_rule_customization();
......@@ -382,12 +353,10 @@ void MainWindow::load_model(const QJsonObject &obj)
prop->accept(visit);
}
ui->grid_view->set_alphabet(alpha);
// On transfère la propriété de ces pointeurs vers Simulation, qui en est désormais propriétaire pour l'exécution de l'automate
simulation.setNeighborhoodRule(m_neighborhood_rule);
simulation.setTransitionRule(m_transition_rule);
simulation.setAlphabet(alpha);
simulation.setAlphabet(ui->grid_view->alphabet());
}
void MainWindow::save_model()
......@@ -418,19 +387,8 @@ void MainWindow::save_model()
root["neighborhood_name"] = ui->neighborhood_list->currentText();
root["neighborhood_data"] = neighborhood_saver.save();
// TODO : sauvegarder l'alphabet quand on pourra y accéder avec Simulation
QJsonArray alphabet;
for (unsigned i = 0; i < simulation.getAlphabet().taille(); ++i)
{
auto state = simulation.getAlphabet().getState(i);
QJsonArray color;
QJsonObject entry;
entry["name"] = QString::fromStdString(state.getStateLabel());
color.push_back(state.getColor().getRed());
color.push_back(state.getColor().getGreen());
color.push_back(state.getColor().getBlue());
entry["color"] = color;
alphabet.push_back(entry);
}
root["alphabet"] = alphabet;
......@@ -469,7 +427,7 @@ static unsigned closest_state(const Alphabet& alph, const QColor& color)
void MainWindow::load_from_image()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),"",tr("Image (*.png *.jpg *.jpeg *.bmp *.gif)"));
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),"",tr("Image (*.png *.jpg *.jpeg *.bmp *.gif"));
QImage img(fileName);
if (img.isNull())
return;
......@@ -490,20 +448,12 @@ void MainWindow::load_from_image()
QJsonObject MainWindow::default_model() const
{
const char* json = R"(
{
"title" : "Game of Life",
"transition_name" : "Game of Life",
"transition_data" : {},
"alphabet" : [
{"name" : "Dead", "color" : [255, 255, 255]},
{"name" : "Alive", "color" : [0, 0, 255]}]
}
)";
QJsonDocument doc = QJsonDocument::fromJson(QByteArray(json));
QJsonObject obj;
obj["title"] = "Game of Life";
obj["transition_name"] = "Game of Life";
obj["transition_data"] = QJsonObject();
return doc.object();
return obj;
}
void MainWindow::on_saveRuleButton_clicked()
......@@ -516,11 +466,3 @@ void MainWindow::on_customize_button_clicked()
enable_rule_customization();
}
void MainWindow::show_neighborhood_widget(bool)
{
NeighborhoodWidget widget(this);
if (!widget.exec())
return;
}
#include "neighborhoodWidget.hpp"
#include "ui_neighborhoodWidget.h"
#include <QDate>
#include <QMessageBox>
NeighborhoodWidget::NeighborhoodWidget(QWidget *parent) :
QWidget(parent), ui(new Ui::NeighborhoodWidget)
{
ui->setupUi(this);
GridView& gv = *(*ui).grid_view;
Alphabet a;
// Création des états à partir du constructeur
state* black = new state(stateColor(0,0,0),"Black");
state* blue = new state(stateColor(0,0,255),"Blue");
state* grey = new state(stateColor(127,127,127),"Grey");
// Ajout des états dans l'Alphabet
a.newEtat(*black);
a.newEtat(*blue);
a.newEtat(*grey);
gv.set_alphabet(a);
QSize size = gv.grid_size();
Coord mileu = {size.width() / 2, size.height() / 2};
Grid newGrid(gv.get_grid());
newGrid.set_cell(mileu, 2);
gv.copy_grid(newGrid);
gv.enable_toggle_mode(1, 0);
// TODO le clic sur la cellule centrale
}
NeighborhoodWidget::~NeighborhoodWidget()
{
delete ui;
}
Neighborhood* NeighborhoodWidget::getVoisinage() const
{
return nullptr;
}
QPushButton* NeighborhoodWidget::getValidateButton() {
return ui->validationButton;
}
#include "neighborhoodWidget.hpp"
#include "ui_neighborhoodWidget.h"
#include <QDate>
#include <QMessageBox>
NeighborhoodWidget::NeighborhoodWidget(QWidget *parent) :
QDialog(parent), ui(new Ui::NeighborhoodWidget)
{
ui->setupUi(this);
/*
// récupérer le nom de l'utilisateur actuel
QString name;
name = qgetenv("USER"); // get the user name in Linux
if (name.isEmpty())
name = qgetenv("USERNAME"); // get the name in Windows
ui->auteur->setText(name);
ui->date->setDate(QDate::currentDate());
*/
}
NeighborhoodWidget::~NeighborhoodWidget()
{
delete ui;
}
void NeighborhoodWidget::done(int r)
{
/*
if(QDialog::Accepted == r) // ok was pressed
{
if(ui->nom->text().isEmpty()) // validate the data somehow
{
QMessageBox::information(this, "Erreur", "Le champ 'Titre' doit être rempli.");
return;
}
else
{
QDialog::done(r);
return;
}
}
else // cancel, close or exc was pressed
{
QDialog::done(r);
return;
} */
}
QString NeighborhoodWidget::voisinage() const
{
return "ui->auteur->text();";
}
......@@ -18,7 +18,7 @@ SOURCES += \
neighborhood_rules/arbitraryneighborhoodrule.cpp \
automaton.cpp \
gridview.cpp \
neihborhoodWidget.cpp \
neighborhoodWidget.cpp \
savingdialog.cpp \
transition_rules/circulartransition.cpp \
transition_rules/lifegametransition.cpp \
......
......@@ -185,10 +185,13 @@ void UIBuilderVisitor::visit(PropertyList &list)
}
});
QObject::connect(widgetGridNeighborhoodButton, &QPushButton::pressed, [&list]() {
NeighborhoodWidget n;
n.show();
NeighborhoodWidget* nw = new NeighborhoodWidget;
nw->show();
QPushButton* validateButton = nw->getValidateButton();
QObject::connect(validateButton, &QPushButton::pressed, [&list] () {
list.clear();
});
});
// J'arrive pas à l'afficher
// QObject::connect(widgetGridNeighborhoodButton, &QPushButton::pressed);
}
}
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