Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Romain De Laage De Bellefaye
LO21-projet
Commits
d03429c5
Verified
Commit
d03429c5
authored
May 27, 2021
by
Romain De Laage De Bellefaye
🌳
Browse files
Merge branch 'master' of gitlab.utc.fr:rdelaage/lo21-projet
parents
e6ab6c53
99260e48
Changes
4
Hide whitespace changes
Inline
Side-by-side
GUI/autocell.cpp
View file @
d03429c5
#include
"autocell.h"
#include
"
Reseau_Cellule_Etat/
reseau_cellule_etats.h"
#include
"reseau_cellule_etats.h"
#include
<QApplication>
#include
<QPushButton>
...
...
@@ -21,6 +21,7 @@
#include
<string>
#include
<QBrush>
#include
<array>
#include
<iostream>
#include
<iomanip>
...
...
@@ -127,15 +128,16 @@ AutoCell::AutoCell(QWidget* parent):QWidget(parent)
general
->
addWidget
(
win_notice
,
0
,
2
,
3
,
1
);
};
void
AutoCell
::
afficherGrille
(
Reseau
&
Grille
)
void
AutoCell
::
afficherGrille
(
Reseau
*
Grille
)
{
win_grid
=
new
QWidget
;
unsigned
int
l
=
Grille
.
getLargeur
();
unsigned
int
h
=
Grille
.
getHauteur
();
unsigned
int
l
=
Grille
->
getLargeur
();
unsigned
int
h
=
Grille
->
getHauteur
();
delete
grid
;
grid
=
new
QTableWidget
(
h
,
l
,
win_grid
);
int
dim_pixels_h
=
32
;
//Taille en pixel.
int
dim_pixels_v
=
30
;
...
...
@@ -146,7 +148,6 @@ void AutoCell::afficherGrille(Reseau& Grille)
grid
->
setVerticalScrollBarPolicy
(
Qt
::
ScrollBarAlwaysOff
);
//Pas de barre pour scroller.
grid
->
setHorizontalScrollBarPolicy
(
Qt
::
ScrollBarAlwaysOff
);
QSize
size
(
30
,
30
);
QFont
serifFont
(
"Times"
,
8
,
QFont
::
DemiBold
);
for
(
unsigned
int
i
=
0
;
i
<
h
;
i
++
){
...
...
@@ -154,39 +155,39 @@ void AutoCell::afficherGrille(Reseau& Grille)
{
//vérifier si les cellules ont ou non été générés (!= nullptr)
QString
indice
;
indice
.
setNum
(
Grille
.
getReseau
()[
i
][
j
].
getIndEtat
());
QString
indice
;
indice
.
setNum
(
Grille
->
getReseau
()[
i
][
j
].
getIndEtat
());
QString
label
;
label
=
QString
::
fromStdString
(
enseEtats
.
getEtat
(
indice
.
toInt
()).
getLabel
());
//label de la cellule
if
(
grid
->
item
(
i
,
j
)
==
nullptr
)
grid
->
setItem
(
i
,
j
,
new
QTableWidgetItem
(
label
));
//if (grid->item(i,j) == nullptr)
grid
->
setItem
(
i
,
j
,
new
QTableWidgetItem
(
indice
));
grid
->
item
(
i
,
j
)
->
setFlags
(
Qt
::
ItemIsEnabled
);
//afficherCellule
QColor
color
;
color
=
enseEtats
.
getEtat
(
indice
.
toInt
()).
getColor
();
//
QColor color(236, 240, 21);
//
afficherCellule
//
QColor color = enseEtats.getEtat(
(Grille.getReseau()[i][j]).getIndEtat()).getColor(); //couleur de la cellule
QColor
color
;
color
=
enseEtats
.
getEtat
(
indice
.
toInt
()).
getColor
();
QBrush
brush_color
;
brush_color
.
setColor
(
color
);
grid
->
item
(
i
,
j
)
->
setBackground
(
brush_color
.
color
());
grid
->
item
(
i
,
j
)
->
setForeground
(
Qt
::
black
);
grid
->
item
(
i
,
j
)
->
setSizeHint
(
size
);
grid
->
item
(
i
,
j
)
->
setFont
(
serifFont
);
grid
->
setColumnWidth
(
j
,
25
);
}
}
connect
(
grid
,
SIGNAL
(
clicked
(
const
QModelIndex
&
)),
this
,
SLOT
(
modifierCellule
(
const
QModelIndex
&
)));
general
->
addWidget
(
win_grid
,
1
,
1
,
2
,
2
);
};
void
AutoCell
::
initialiserGrille
(){
delete
Grille
;
bool
ok
;
int
l
=
(
edit_largeur
->
text
()).
toInt
(
&
ok
,
10
);
...
...
@@ -196,12 +197,13 @@ void AutoCell::initialiserGrille(){
QString
str_l
;
str_l
.
setNum
(
l
);
QString
str_h
;
str_h
.
setNum
(
h
);
Reseau
Grille1
(
h
,
l
);
//Reseau Grille1(12,12);
this
->
Grille
=
new
Reseau
(
h
,
l
);
this
->
afficherGrille
(
Grille1
);
if
(
check_aleatoire
->
isChecked
())
Grille
->
setAleatoire
(
);
};
//méthode à implémenter qui récupère les données du formulaire - penser à réinitialiser les données annexes
this
->
afficherGrille
(
this
->
Grille
);
};
void
AutoCell
::
RAZ
(){
...
...
@@ -210,3 +212,44 @@ void AutoCell::RAZ(){
edit_largeur
->
setText
(
""
);
edit_hauteur
->
setText
(
""
);
}
void
AutoCell
::
modifierCellule
(
const
QModelIndex
&
index
)
{
unsigned
int
i
=
index
.
row
();
unsigned
int
j
=
index
.
column
();
//bool ok;
Grille
->
getReseau
()[
i
][
j
].
incrementerEtat
();
unsigned
int
indice
=
(
Grille
->
getReseau
()[
i
][
j
].
getIndEtat
());
//QString str_indice0 ; str_indice0 = grid -> item(i,j)->text();
//QString inc = "1";
//unsigned int indice = (((grid -> item(i,j)))->text().toInt(&ok1,10));//enseEtats.getNbEtats();
//unsigned int* ind = const_cast<unsigned int*>(&indice);
//++*ind;
//unsigned int inc = 1;
//ind->operator+=(inc);
/// VISIBLEMENT LE PROGRAMME AJOUTE LA LARGEUR * HAUTEUR A L'INCREMENTATION ??? POURQUOI ???
//indice = ++inc; => problémé lié à la duplication du signal
//unsigned int n = enseEtats.getNbEtats();
QString
str_indice
;
str_indice
.
setNum
(
indice
,
10
);
QColor
color
;
color
=
enseEtats
.
getEtat
(
indice
).
getColor
();
//QString str_indice = str_indice0 + inc;
QBrush
brush_color
;
brush_color
.
setColor
(
color
);
grid
->
item
(
i
,
j
)
->
setBackground
(
brush_color
.
color
());
grid
->
item
(
i
,
j
)
->
setText
(
str_indice
);
//afficherGrille(Grille);
//qApp->quit();
}
GUI/autocell.h
View file @
d03429c5
#ifndef AUTOCELL_H
#define AUTOCELL_H
#include
"
Reseau_Cellule_Etat/
reseau_cellule_etats.h"
#include
"reseau_cellule_etats.h"
#include
<QObject>
#include
<QApplication>
#include
<QPushButton>
#include
<QWidget>
...
...
@@ -27,6 +28,8 @@ extern EnsembleEtat& enseEtats;
class
AutoCell
:
public
QWidget
{
Reseau
*
Grille
=
nullptr
;
Q_OBJECT
QGridLayout
*
general
;
...
...
@@ -73,12 +76,17 @@ class AutoCell : public QWidget
//void chargerGrille();
//void listerGrille(); //déjà réfléchir à la recopie
//Reseau initialiserGrille(); //méthode à implémenter qui récupère les données du formulaire - penser à réinitialiser les données annexes
void
afficherGrille
(
Reseau
&
);
//affiche une grille
//void afficherGrille(Reseau&); //affiche une grille
void
afficherGrille
(
Reseau
*
Grille
);
void
initialiserGrille
();
void
RAZ
();
//void faireSimulation();
//void sauvegarderGrille();
//void modifierGrille();//à implémenter
//Reseau& modifierCellule(const QModelIndex&, Reseau& Grille);//à implémenter
void
modifierCellule
(
const
QModelIndex
&
index
);
};
...
...
Reseau_Cellule_Etat/reseau_cellule_etats.cpp
View file @
d03429c5
#include
"reseau_cellule_etats.h"
#include
<iostream>
#include
<iomanip>
#include
<cstdlib>
extern
EnsembleEtat
&
enseEtats
;
using
namespace
std
;
...
...
@@ -70,6 +73,9 @@ void Cellule::initCellule(const unsigned int ind, const unsigned int &x, const u
this
->
ord
=
y
;
}
void
Cellule
::
incrementerEtat
(){
indEtat
=
(
indEtat
+
1
)
%
enseEtats
.
getNbEtats
();}
//méthodes de la classe Reseau
Reseau
::
Reseau
(
const
unsigned
int
&
h
,
const
unsigned
int
&
l
)
:
hauteur
(
h
),
largeur
(
l
){
...
...
@@ -95,3 +101,29 @@ void Reseau::affiche(){
std
::
cout
<<
"
\n
"
;
}
}
Reseau
&
Reseau
::
setAleatoire
(){
srand
(
time
(
NULL
));
for
(
unsigned
int
i
=
0
;
i
<
hauteur
;
i
++
)
for
(
unsigned
int
j
=
0
;
j
<
largeur
;
j
++
)
{
unsigned
int
random_ind
=
rand
()
%
(
enseEtats
.
getNbEtats
());
reseau
[
i
][
j
].
initCellule
(
random_ind
,
i
,
j
);
};
return
*
this
;
}
Reseau
::
Reseau
(
Reseau
&
init_grille
){
hauteur
=
init_grille
.
hauteur
;
largeur
=
init_grille
.
largeur
;
reseau
=
new
Cellule
*
[
hauteur
];
for
(
unsigned
int
i
=
0
;
i
<
hauteur
;
i
++
)
reseau
[
i
]
=
new
Cellule
[
largeur
];
for
(
unsigned
int
i
=
0
;
i
<
hauteur
;
i
++
)
for
(
unsigned
int
j
=
0
;
j
<
largeur
;
j
++
)
{
reseau
[
i
][
j
].
initCellule
(
init_grille
.
reseau
[
i
][
j
].
getIndEtat
(),
i
,
j
);
}
};
Reseau_Cellule_Etat/reseau_cellule_etats.h
View file @
d03429c5
...
...
@@ -20,6 +20,7 @@ private:
public:
inline
unsigned
int
getIndEtat
()
const
{
return
indEtat
;}
void
incrementerEtat
();
};
class
Etat
{
...
...
@@ -27,15 +28,15 @@ private:
unsigned
int
indice
;
std
::
string
label
;
QColor
color
;
inline
Etat
(
unsigned
int
ind
,
std
::
string
lab
,
int
r
=
0
,
int
g
=
0
,
int
b
=
0
)
:
Etat
(
unsigned
int
ind
,
std
::
string
lab
,
int
r
=
0
,
int
g
=
0
,
int
b
=
0
)
:
indice
(
ind
),
label
(
lab
),
color
(
r
,
g
,
b
){};
inline
Etat
(
unsigned
int
ind
,
std
::
string
lab
,
QColor
col
)
:
Etat
(
unsigned
int
ind
,
std
::
string
lab
,
QColor
col
)
:
indice
(
ind
),
label
(
lab
),
color
(
col
){};
//constructeur privé (l'utilisateur ne doit pas pouvoir créer un Etat par ce biais)
friend
class
EnsembleEtat
;
public:
inline
std
::
string
getLabel
(){
return
label
;}
inline
QColor
getColor
(){
return
color
;}
std
::
string
getLabel
(){
return
label
;}
QColor
getColor
(){
return
color
;}
};
...
...
@@ -61,7 +62,8 @@ public:
static
EnsembleEtat
&
getInstance
();
static
void
libererInstance
();
void
initEtat
(
const
Etat
*
init_etats
=
nullptr
);
//initialisation du tableau d'Etats à partir d'un tableau externe
inline
Etat
&
getEtat
(
const
unsigned
int
&
ind
){
return
*
ensEtats
[
ind
];}
Etat
&
getEtat
(
const
unsigned
int
&
ind
){
return
*
ensEtats
[
ind
];}
unsigned
int
getNbEtats
()
const
{
return
nbEtats
;};
};
class
Reseau
{
...
...
@@ -69,23 +71,14 @@ private:
unsigned
int
hauteur
;
unsigned
int
largeur
;
Cellule
**
reseau
;
friend
class
RegleVoisinage
;
friend
class
RegleVoisinageNeumann
;
friend
class
RegleVoisinageMoore
;
public:
/* inline Reseau(const unsigned int &h, const unsigned int &l):hauteur(h),largeur(l){
reseau = new Cellule* [hauteur];
for(unsigned int i=0; i<hauteur; i++)
reseau[i] = new Cellule [largeur];
for(unsigned int i=0; i<hauteur; i++) //initialisation des cellules dans un second temps car pas possible avec l'allocation dynamique
for(unsigned int j=0; j<largeur; j++)
reseau[i][j].initCellule(0,i,j);
}*/
inline
int
getLargeur
()
const
{
return
largeur
;};
inline
int
getHauteur
()
const
{
return
hauteur
;};
inline
Cellule
**
getReseau
()
const
{
return
reseau
;};
int
getLargeur
()
const
{
return
largeur
;};
int
getHauteur
()
const
{
return
hauteur
;};
Reseau
&
setAleatoire
();
Cellule
**
getReseau
()
const
{
return
reseau
;};
Reseau
(
const
unsigned
int
&
h
,
const
unsigned
int
&
l
);
Reseau
(
Reseau
&
);
~
Reseau
();
void
affiche
();
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment