1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include "mainwindow.h"
#include<QBoxLayout>
#include<QSpinBox>
#include<QApplication>
#include<QFrame>
#include<QFormLayout>
#include<QComboBox>
#include<QFile>
#include<QString>
#include<QPushButton>
#include<QTextLine>
#include<QLabel>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
QFrame *frame =new QFrame;
setCentralWidget(frame);
QBoxLayout*lay=new QBoxLayout(QBoxLayout::TopToBottom,frame);
QLabel *label = new QLabel("Produit ");
QLabel *label1 = new QLabel("Prix d'achat ");
QLabel *label2 = new QLabel("Prix de vente ");
QLabel *label3 = new QLabel("Stock ");
comboBox_Produit = new QComboBox;
spinBox_prixVente = new QSpinBox;
spinBox_prixAchat = new QSpinBox;
spinBox_stocks = new QSpinBox;
lay->addWidget(label);
lay->addWidget(comboBox_Produit);
lay->addWidget(label1);
lay->addWidget(spinBox_prixAchat);
lay->addWidget(label2);
lay->addWidget(spinBox_prixVente);
lay->addWidget(label3);
lay->addWidget(spinBox_stocks);
lay->addStretch();
QHBoxLayout*lay1=new QHBoxLayout;
QPushButton*b1=new QPushButton("Sauver");
lay1->addWidget(b1);
QPushButton*b2=new QPushButton("Quitter");
connect(b1,SIGNAL(clicked(),qApp,SLOT(quit()));
lay1->addWidget(b2);
lay->addLayout(lay1);
//Mise à jour du produit lorsque la séléction change
connect(comboBox_Produit, &QComboBox::currentIndexChanged, this, &MainWindow::slotComboBox_currentIndexChanged);
//Chargement des produits dans la combobox
load();
}
int MainWindow::find( const QString& nomP)
{
for( int k = 0 ; k < r.size() ; ++k)
if( nomP == r[k].nom() )
return k ;
return -1 ;
}
//Le constructeur est déjà défini au début de ce fichier, il
//n'est pas possible de le définir une seconde fois
//MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
void MainWindow::load()
{
//ouvrir un fichier ayant l'extension .csv
r = lireProduits(QFileDialog::getOpenFileName(this,"Open File", ".",".csv"));
if(!r.isEmpty()){
comboBox_Produit->clear();
for(const auto & p :r) //je récupère le nom du produit et l'insère dans la comboBox
comboBox_Produit->addItem(p.nom());
//comboBox_Produit->addItem(Produit.nom());
//ComboBox *C1->setcurrentindex(0,r);
//???????????????????????????? la ou je beugue
Produit p = r.first();
comboBox_Produit->setCurrentIndex(0);
}
}
void MainWindow::slotComboBox_currentIndexChanged(int index)
{
Produit p = r.at(index);
spinBox_prixAchat->setValue(p.pachat());
spinBox_prixVente->setValue(p.pvente());
spinBox_stocks->setEnabled(p.isValid());
if(p.isValid())
spinBox_stocks->setValue(p.stock());
} |
Partager