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
1235ab97
Verified
Commit
1235ab97
authored
Jun 10, 2021
by
Romain De Laage De Bellefaye
🌳
Browse files
connect click and initAuto
parent
184fa06f
Changes
4
Hide whitespace changes
Inline
Side-by-side
includes/autocell.h
View file @
1235ab97
...
...
@@ -116,6 +116,7 @@ class AutoCell : public QWidget
void
sauvegarderGrille
();
void
defNouveauModele
();
void
afficherErreur
(
QString
&
msg
);
void
initAutomate
(
const
QString
&
name
);
};
#endif // AUTOCELL_H
includes/autosql.h
View file @
1235ab97
...
...
@@ -41,7 +41,7 @@ class Database {
void
saveFunction
(
const
QString
&
name
,
const
Fonction
&
f
)
const
;
void
saveVoisinage
(
const
QString
&
name
,
const
RegleVoisinage
&
r
)
const
;
void
saveEnsemble
(
Automate
&
a
)
const
;
void
initSingletonAutomate
(
QString
&
modele
)
const
;
void
initSingletonAutomate
(
const
QString
&
modele
)
const
;
};
#endif
src/autocell.cpp
View file @
1235ab97
...
...
@@ -76,6 +76,7 @@ AutoCell::AutoCell(QWidget* parent):QWidget(parent)
connect
(
liste
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
RAZ
()));
connect
(
liste
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
chargerGrilles
()));
connect
(
liste
,
SIGNAL
(
currentTextChanged
(
const
QString
&
)),
this
,
SLOT
(
initAutomate
(
const
QString
&
)));
grid_model_choice
=
new
QGridLayout
(
win_model_choice
);
...
...
@@ -381,3 +382,8 @@ void AutoCell::afficherErreur(QString& msg){
messageBox
.
critical
(
0
,
"Error"
,
msg
);
messageBox
.
setFixedSize
(
500
,
200
);
}
void
AutoCell
::
initAutomate
(
const
QString
&
name
)
{
std
::
cout
<<
name
.
toStdString
()
<<
std
::
endl
;
Database
::
getInstance
().
initSingletonAutomate
(
name
);
}
src/autosql.cpp
View file @
1235ab97
...
...
@@ -234,6 +234,8 @@ Reseau& Database::getReseau(int idReseau) const {
reseau
.
prepare
(
"SELECT * FROM reseaux WHERE id = :id"
);
reseau
.
bindValue
(
":id"
,
idReseau
);
reseau
.
exec
();
if
(
!
reseau
.
first
())
throw
"Can't select!"
;
Reseau
*
r
=
new
Reseau
(
reseau
.
value
(
"h"
).
toUInt
(),
reseau
.
value
(
"l"
).
toUInt
());
//remplissage du réseau
...
...
@@ -247,6 +249,8 @@ Reseau& Database::getReseau(int idReseau) const {
cellule
.
bindValue
(
":i"
,
static_cast
<
int
>
(
i
));
cellule
.
bindValue
(
":j"
,
static_cast
<
int
>
(
j
));
cellule
.
exec
();
if
(
!
cellule
.
first
())
throw
"Can't select!"
;
while
(
static_cast
<
int
>
(
r
->
getReseau
()[
i
][
j
].
getIndEtat
())
!=
cellule
.
value
(
"etat"
).
toInt
())
r
->
getReseau
()[
i
][
j
].
incrementerEtat
();
}
...
...
@@ -414,6 +418,8 @@ void Database::saveEnsemble(Automate& a) const {
QSqlQuery
query
(
db
);
query
.
prepare
(
"SELECT COUNT(*) FROM EnsembleEtats"
);
query
.
exec
();
if
(
!
query
.
first
())
throw
"Error sql!"
;
int
idEns
=
query
.
value
(
0
).
toInt
()
+
1
;
//Insertion du tuple dans EnsembleEtats
...
...
@@ -454,6 +460,8 @@ void Database::stockerReseau(const Reseau& reseau, const QString& nomReseau, con
QSqlQuery
query
(
db
);
query
.
prepare
(
"SELECT COUNT(*) FROM reseaux"
);
query
.
exec
();
if
(
!
query
.
first
())
throw
"error sql!"
;
int
idReseau
=
query
.
value
(
0
).
toInt
()
+
1
;
//Insertion du tuple dans reseaux
...
...
@@ -480,24 +488,27 @@ void Database::stockerReseau(const Reseau& reseau, const QString& nomReseau, con
}
}
void
Database
::
initSingletonAutomate
(
QString
&
modele
)
const
void
Database
::
initSingletonAutomate
(
const
QString
&
modele
)
const
{
Automate
::
getInstance
().
reinitialiserAutomate
();
QSqlQuery
reseau
(
db
);
reseau
.
prepare
(
"SELECT
*
FROM automates WHERE nom = :id"
);
reseau
.
prepare
(
"SELECT
nom, auteur, description, annee
FROM automates WHERE nom = :id"
);
reseau
.
bindValue
(
":id"
,
modele
);
reseau
.
exec
();
Automate
::
getInstance
().
setTitle
(
reseau
.
value
(
"nom"
).
toString
().
toStdString
());
Automate
::
getInstance
().
setAuthor
(
reseau
.
value
(
"auteur"
).
toString
().
toStdString
());
Automate
::
getInstance
().
setDesc
(
reseau
.
value
(
"description"
).
toString
().
toStdString
());
Automate
::
getInstance
().
setYear
(
reseau
.
value
(
"annee"
).
toInt
());
if
(
!
reseau
.
first
())
throw
"Can't select!"
;
Automate
::
getInstance
().
setTitle
(
reseau
.
value
(
0
).
toString
().
toStdString
());
Automate
::
getInstance
().
setAuthor
(
reseau
.
value
(
1
).
toString
().
toStdString
());
Automate
::
getInstance
().
setDesc
(
reseau
.
value
(
2
).
toString
().
toStdString
());
Automate
::
getInstance
().
setYear
(
reseau
.
value
(
3
).
toInt
());
Database
::
initEnsEtat
(
Automate
::
getInstance
());
Automate
::
getInstance
().
setFonction
(
*
Database
::
getFonction
(
Automate
::
getInstance
()));
Automate
::
getInstance
().
setRegleVoisinage
(
*
Database
::
getRegleVoisinage
(
modele
));
Database
::
initEnsEtat
(
Automate
::
getInstance
());
//Automate::getInstance().getEnsemble();
std
::
vector
<
QString
>
reseaux
=
Database
::
getListeReseaux
(
modele
);
...
...
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