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
f78676bb
Commit
f78676bb
authored
Jun 06, 2021
by
Boris Cazic
Browse files
Update autocell.cpp
parent
fb96e85a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/autocell.cpp
View file @
f78676bb
#include
"autocell.h"
#include
"reseau_cellule_etats.h"
#include
"autosql.h"
#include
"Automate.h"
#include
<QApplication>
#include
<QPushButton>
...
...
@@ -44,38 +42,28 @@ AutoCell::AutoCell(QWidget* parent):QWidget(parent)
//définition de la frame choix du modèle
win_model_choice
=
new
QWidget
;
win_model_choice
->
setStyleSheet
(
"background-color: rgb(204, 209, 209)"
);
win_model_choice
->
setFixedSize
(
300
,
100
);
lab_model_choice
=
new
QLabel
(
"Choisir un modèle dans la liste ou
\n
en paramétrer un nouveau :"
,
win_model_choice
);
button_add_model
=
new
QPushButton
(
"Ajouter un modèle"
);
button_add_model
->
setToolTip
(
"Configurer un nouveau modèle"
);
button_add_model
->
setStyleSheet
(
"background-color : rgb(251, 252, 252 )"
);
button_add_model
->
setFixedWidth
(
140
);
liste
=
new
QComboBox
(
win_model_choice
);
liste
->
setPlaceholderText
(
"--- select ---"
);
// récupération des automates en mémoire
/*vector<QString> noms_modeles = database.getAutomates();
for(auto : nom, noms_modeles){
liste->addItem(nom);
}*/
liste
->
addItem
(
"modèle 1"
);
liste
->
addItem
(
"modèle 2"
);
liste
->
addItem
(
"modèle 3"
);
liste
->
addItem
(
"modèle 4"
);
liste
->
setStyleSheet
(
"background-color : rgb(251, 252, 252 )"
);
liste
->
setFixedWidth
(
140
);
connect
(
liste
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
RAZ
()));
connect
(
liste
,
SIGNAL
(
currentTextChanged
(
const
QString
&
text
)),
this
,
SLOT
(
chargerGrilles
(
const
QString
&
text
)));
grid_model_choice
=
new
QGridLayout
(
win_model_choice
);
grid_model_choice
->
addWidget
(
lab_model_choice
,
0
,
0
,
1
,
2
);
...
...
@@ -135,45 +123,34 @@ AutoCell::AutoCell(QWidget* parent):QWidget(parent)
grid_run_control
->
setColumnMinimumWidth
(
1
,
100
);
grid_run_control
->
setColumnMinimumWidth
(
2
,
100
);
grid_run_control
->
setRowMinimumHeight
(
3
,
80
);
grid_run_control
->
setRowMinimumHeight
(
4
,
400
);
grid_run_control
->
setRowMinimumHeight
(
3
,
400
);
grid_run_control
->
addWidget
(
lab_run_crtl
,
0
,
0
,
1
,
3
,
Qt
::
AlignTop
);
grid_run_control
->
addWidget
(
lab_run_crtl
,
0
,
0
,
1
,
3
);
lab_time_step
=
new
QLabel
(
"Pas de temps : "
);
edit_time_step
=
new
QLineEdit
;
edit_time_step
->
setStyleSheet
(
"background-color: rgb(255,255,255)"
);
edit_time_step
->
setFixedWidth
(
30
);
edit_time_step
->
setText
(
"1"
);
//valeur par défaut pour le pas de temps
button_valider_delai
=
new
QPushButton
(
"valider"
);
button_valider_delai
->
setStyleSheet
(
"background-color: rgb(255,255,255)"
);
button_valider_delai
->
setFixedWidth
(
50
);
//connect(button_valider_delai, SIGNAL(clicked()), Automate::getInstance(), SLOT(Automate::getInstance().setDelai()));
button_prev
=
new
QPushButton
(
"<<"
);
button_prev
->
setStyleSheet
(
"background-color: rgb(255,255,255)"
);
button_prev
->
setFixedSize
(
40
,
40
);
button_run
=
new
QPushButton
(
"RUN"
);
button_run
->
setFixedSize
(
40
,
40
);
button_run
->
setStyleSheet
(
"background-color: rgb(255,255,255)"
);
connect
(
button_run
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
gererSimulation
()));
button_next
=
new
QPushButton
(
">>"
);
button_next
->
setFixedSize
(
40
,
40
);
button_next
->
setStyleSheet
(
"background-color: rgb(255,255,255)"
);
button_reinitialiser
=
new
QPushButton
(
"Réinitialiser la simulation"
);
button_reinitialiser
->
setStyleSheet
(
"background-color: rgb(255,255,255)"
);
button_reinitialiser
->
setFixedWidth
(
200
);
grid_run_control
->
addWidget
(
lab_time_step
,
1
,
0
);
grid_run_control
->
addWidget
(
edit_time_step
,
1
,
1
);
grid_run_control
->
addWidget
(
button_valider_delai
,
1
,
2
);
grid_run_control
->
addWidget
(
button_prev
,
2
,
0
);
grid_run_control
->
addWidget
(
button_run
,
2
,
1
);
grid_run_control
->
addWidget
(
button_next
,
2
,
2
);
grid_run_control
->
addWidget
(
button_reinitialiser
,
3
,
0
,
Qt
::
AlignCenter
);
button_save_grid
=
new
QPushButton
(
"sauvegarder la grille"
);
grid_run_control
->
addWidget
(
button_save_grid
,
4
,
1
,
4
,
3
,
Qt
::
AlignBottom
);
grid_run_control
->
addWidget
(
button_save_grid
,
3
,
1
,
4
,
3
,
Qt
::
AlignBottom
);
general
->
addWidget
(
win_run_ctrl
,
1
,
0
,
2
,
1
);
...
...
@@ -204,8 +181,8 @@ void AutoCell::afficherGrille(Reseau* Grille)
delete
grid
;
grid
=
new
QTableWidget
(
h
,
l
,
win_grid
);
int
dim_pixels_h
=
40
;
//Taille en pixel.
int
dim_pixels_v
=
4
0
;
int
dim_pixels_h
=
32
;
//Taille en pixel.
int
dim_pixels_v
=
3
0
;
grid
->
setFixedSize
((
l
)
*
dim_pixels_h
,
h
*
dim_pixels_v
);
...
...
@@ -214,21 +191,23 @@ void AutoCell::afficherGrille(Reseau* Grille)
grid
->
setVerticalScrollBarPolicy
(
Qt
::
ScrollBarAlwaysOff
);
//Pas de barre pour scroller.
grid
->
setHorizontalScrollBarPolicy
(
Qt
::
ScrollBarAlwaysOff
);
grid
->
horizontalHeader
()
->
setSectionResizeMode
(
QHeaderView
::
Fixed
);
QFont
serifFont
(
"Times"
,
8
,
QFont
::
DemiBold
);
for
(
unsigned
int
i
=
0
;
i
<
h
;
i
++
){
for
(
unsigned
int
j
=
0
;
j
<
l
;
j
++
)
{
//vérifier si les cellules ont ou non été générés (!= nullptr)
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
(
indice
));
grid
->
item
(
i
,
j
)
->
setFlags
(
Qt
::
ItemIsEnabled
);
//afficherCellule
QColor
color
;
color
=
enseEtats
.
getEtat
(
indice
.
toInt
()).
getColor
();
...
...
@@ -239,9 +218,9 @@ void AutoCell::afficherGrille(Reseau* Grille)
grid
->
item
(
i
,
j
)
->
setBackground
(
brush_color
.
color
());
grid
->
item
(
i
,
j
)
->
setForeground
(
Qt
::
black
);
grid
->
item
(
i
,
j
)
->
setFont
(
serifFont
);
grid
->
setColumnWidth
(
j
,
40
);
grid
->
setColumnWidth
(
j
,
25
);
}
grid
->
setRowHeight
(
i
,
40
);
}
connect
(
grid
,
SIGNAL
(
clicked
(
const
QModelIndex
&
)),
this
,
SLOT
(
modifierCellule
(
const
QModelIndex
&
)));
general
->
addWidget
(
win_grid
,
1
,
1
,
2
,
2
);
...
...
@@ -255,6 +234,7 @@ void AutoCell::initialiserGrille(){
bool
ok
;
int
l
=
(
edit_largeur
->
text
()).
toInt
(
&
ok
,
10
);
int
h
=
(
edit_hauteur
->
text
()).
toInt
(
&
ok
,
10
);
QString
str_l
;
str_l
.
setNum
(
l
);
...
...
@@ -264,18 +244,6 @@ void AutoCell::initialiserGrille(){
if
(
check_aleatoire
->
isChecked
())
Grille
->
setAleatoire
();
QString
nom_grille
=
list_grids
->
currentText
();
/*if (check_load_grid->isChecked()) {
delete Grille;
Grille = new Reseau(getGrilleFromDb(nom_grille)) /// Méthode à implémenter
QString str_largeur;
QString str_hauteur;
edit_largeur->setText(str_largeur.setNum(Grille.getLargeur,10);
edit_hauteur->setText(str_hauteur.setNum(Grille.getHauteur,10);
}*/
//réinitialiser l'automate
this
->
afficherGrille
(
this
->
Grille
);
};
...
...
@@ -287,44 +255,45 @@ void AutoCell::RAZ(){
edit_largeur
->
setText
(
""
);
edit_hauteur
->
setText
(
""
);
edit_time_step
->
setText
(
"1"
);
check_aleatoire
->
setCheckState
(
Qt
::
Unchecked
);
check_load_grid
->
setCheckState
(
Qt
::
Unchecked
);
;}
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
);
//réitnitialiser l'automate ou modif du buffer d
}
void
AutoCell
::
chargerGrilles
(
const
QString
&
text
){
list_grids
->
clear
();
/*vector<QString> noms = database.getListesReseaux(text);
for(auto nom : noms) list_grids->addItem(nom);*/
}
//afficherGrille(Grille);
void
AutoCell
::
gererSimulation
(){
if
(
button_run
->
text
()
==
"RUN"
){
button_run
->
setText
(
"STOP"
);
//Automate::getInstance().start();
}
else
{
button_run
->
setText
(
"RUN"
);
//Automate::getInstance().pause();
}
//qApp->quit();
}
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