Première tranche verticale : domaine circuit via DataProvider/API
This commit is contained in:
+183
@@ -0,0 +1,183 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
|
||||
import qt.koriolan.shipheart 1.0
|
||||
|
||||
// ============================================================================
|
||||
// home.qml (EMBRYON - POC WASM production, domaine circuit uniquement)
|
||||
// ----------------------------------------------------------------------------
|
||||
// Version très réduite du vrai home.qml (~3880 lignes, tous domaines) :
|
||||
// couvre uniquement l'affichage des circuits, via l'API réelle (DataProvider)
|
||||
// au lieu de bdd.*. Objectif : valider la chaîne complète (HTTP réel, JSON,
|
||||
// affichage QML) sur un seul domaine avant de généraliser.
|
||||
//
|
||||
// Simplifications volontaires par rapport au vrai home.qml :
|
||||
// - Lecture seule (pas de changement de consigne au clic - l'endpoint
|
||||
// d'écriture n'est pas encore construit côté API, cf synthèse §20.7)
|
||||
// - Un seul domaine affiché (pas de batteries/réservoirs/capteurs/pages
|
||||
// personnalisées/messages/réveils/minuteur)
|
||||
// - Délégué d'affichage simplifié (pas Shipheart_bouton_circuit, qui
|
||||
// embarque des actions d'écriture non encore branchées)
|
||||
// - mise_a_jour_onglets_circuits() n'existe plus : l'API renvoie déjà
|
||||
// l'état agrégé par famille dans /elements/familles (cf §20.7/21.5)
|
||||
// ============================================================================
|
||||
|
||||
Shipheart_page {
|
||||
id: page_accueil
|
||||
|
||||
readonly property int deport_haut_masquage_onglets: 20
|
||||
readonly property int rayon_onglets: 20
|
||||
property int nombre_colonnes_affichage_circuits: 2
|
||||
property int nombre_circuits_affiches_sur_une_colonne: 4
|
||||
property int id_groupe_circuits: 0
|
||||
|
||||
ListModel { id: modele_onglets_circuits }
|
||||
ListModel { id: modele_circuits }
|
||||
|
||||
property DataProvider dataProvider: DataProvider {}
|
||||
|
||||
Connections {
|
||||
target: dataProvider
|
||||
|
||||
function onFamillesRecues(familles) {
|
||||
modele_onglets_circuits.clear();
|
||||
for (var i = 0; i < familles.length; i++) {
|
||||
var f = familles[i];
|
||||
modele_onglets_circuits.append({
|
||||
"id": f.id,
|
||||
"libelle": f.nom,
|
||||
"etat": f.etat,
|
||||
"actif": (f.id === id_groupe_circuits)
|
||||
});
|
||||
// Sélectionne la première famille par défaut si aucune n'est choisie :
|
||||
if (id_groupe_circuits === 0 && i === 0) {
|
||||
id_groupe_circuits = f.id;
|
||||
dataProvider.get_elements("circuit", id_groupe_circuits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onElementsRecus(elements) {
|
||||
modele_circuits.clear();
|
||||
for (var j = 0; j < elements.length; j++) {
|
||||
modele_circuits.append(elements[j]);
|
||||
}
|
||||
}
|
||||
|
||||
function onErreur(message) {
|
||||
console.log("DataProvider erreur : " + message);
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
dataProvider.get_familles("circuit");
|
||||
}
|
||||
|
||||
// Rafraîchissement périodique (remplace mise_a_jour_circuits(), appelée chaque seconde côté natif) :
|
||||
Timer {
|
||||
interval: 1000
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
if (id_groupe_circuits > 0) dataProvider.get_elements("circuit", id_groupe_circuits);
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
spacing: 10
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// Onglets (familles) :
|
||||
Rectangle {
|
||||
id: onglets_circuits
|
||||
Layout.fillWidth: true
|
||||
height: shipheart_hauteur_bandeau_haut
|
||||
color: "transparent"
|
||||
visible: modele_onglets_circuits.count > 1
|
||||
|
||||
GridView {
|
||||
id: grille_onglets_circuits
|
||||
anchors.fill: parent
|
||||
cellWidth: width / Math.max(1, Math.min(modele_onglets_circuits.count, 5))
|
||||
cellHeight: shipheart_hauteur_bandeau_haut
|
||||
model: modele_onglets_circuits
|
||||
clip: true
|
||||
|
||||
delegate: Rectangle {
|
||||
width: grille_onglets_circuits.cellWidth - 2
|
||||
height: grille_onglets_circuits.cellHeight
|
||||
radius: rayon_onglets
|
||||
color: model.actif ? shipheart_couleur_fond_bouton_actif : shipheart_couleur_fond_bouton
|
||||
|
||||
Text {
|
||||
text: model.libelle
|
||||
anchors.centerIn: parent
|
||||
color: couleur_blanc_casse
|
||||
font.pixelSize: 14
|
||||
font.bold: model.actif
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
id_groupe_circuits = model.id;
|
||||
for (var k = 0; k < modele_onglets_circuits.count; k++) {
|
||||
modele_onglets_circuits.set(k, {"actif": (modele_onglets_circuits.get(k).id === model.id)});
|
||||
}
|
||||
dataProvider.get_elements("circuit", id_groupe_circuits);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// Circuits de la famille sélectionnée :
|
||||
GridView {
|
||||
id: circuits_grid
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
cellWidth: width / nombre_colonnes_affichage_circuits
|
||||
cellHeight: height / nombre_circuits_affiches_sur_une_colonne
|
||||
model: modele_circuits
|
||||
clip: true
|
||||
|
||||
delegate: Rectangle {
|
||||
width: circuits_grid.cellWidth - 4
|
||||
height: circuits_grid.cellHeight - 4
|
||||
radius: 10
|
||||
color: shipheart_couleur_fond_bouton
|
||||
border.color: (model.etat === 2) ? "red" : (model.etat === 1) ? "orange" : "transparent"
|
||||
border.width: 2
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
spacing: 4
|
||||
|
||||
Text {
|
||||
text: model.nom
|
||||
color: couleur_blanc_casse
|
||||
font.pixelSize: 14
|
||||
font.bold: true
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
Text {
|
||||
text: model.tension.toFixed(1) + " V " + model.intensite.toFixed(2) + " A"
|
||||
color: couleur_blanc_casse
|
||||
font.pixelSize: 12
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
anchors.centerIn: parent
|
||||
visible: circuits_grid.count === 0
|
||||
text: qsTr("Aucun circuit dans ce groupe.")
|
||||
color: couleur_rouge_transparent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user