diff --git a/deuchnord-hermes.pro.user b/deuchnord-hermes.pro.user
index 3f8063e..2eaa3b5 100644
--- a/deuchnord-hermes.pro.user
+++ b/deuchnord-hermes.pro.user
@@ -1,251 +1,260 @@
-
-
-
-
-
- ProjectExplorer.Project.ActiveTarget
- 0
-
-
- ProjectExplorer.Project.EditorSettings
-
- true
- false
- true
-
- Cpp
-
- CppGlobal
-
-
-
- QmlJS
-
- QmlJSGlobal
-
-
- 2
- UTF-8
- false
- 4
- false
- 80
- true
- true
- 1
- true
- false
- 0
- true
- 0
- 8
- true
- 1
- true
- true
- true
- false
-
-
-
- ProjectExplorer.Project.PluginSettings
-
-
-
- ProjectExplorer.Project.Target.0
-
- Desktop Qt 5.2.1 MinGW 32bit
- Desktop Qt 5.2.1 MinGW 32bit
- qt.521.win32_mingw48.essentials_kit
- 1
- 0
- 0
-
- C:/Users/Jérôme/Dropbox/Git/Hermes/build-deuchnord-hermes-Desktop_Qt_5_2_1_MinGW_32bit-Debug
-
-
- true
- qmake
-
- QtProjectManager.QMakeBuildStep
- false
- true
-
- false
-
-
- true
- Make
-
- Qt4ProjectManager.MakeStep
-
- false
-
-
-
- 2
- Compiler
-
- ProjectExplorer.BuildSteps.Build
-
-
-
- true
- Make
-
- Qt4ProjectManager.MakeStep
-
- true
- clean
-
-
- 1
- Nettoyer
-
- ProjectExplorer.BuildSteps.Clean
-
- 2
- false
-
- Debug
-
- Qt4ProjectManager.Qt4BuildConfiguration
- 2
- true
-
-
- C:/Users/Jérôme/Dropbox/Git/Hermes/build-deuchnord-hermes-Desktop_Qt_5_2_1_MinGW_32bit-Release
-
-
- true
- qmake
-
- QtProjectManager.QMakeBuildStep
- false
- true
-
- false
-
-
- true
- Make
-
- Qt4ProjectManager.MakeStep
-
- false
-
-
-
- 2
- Compiler
-
- ProjectExplorer.BuildSteps.Build
-
-
-
- true
- Make
-
- Qt4ProjectManager.MakeStep
-
- true
- clean
-
-
- 1
- Nettoyer
-
- ProjectExplorer.BuildSteps.Clean
-
- 2
- false
-
- Release
-
- Qt4ProjectManager.Qt4BuildConfiguration
- 0
- true
-
- 2
-
-
- 0
- Déploiement
-
- ProjectExplorer.BuildSteps.Deploy
-
- 1
- Déployer localement
-
- ProjectExplorer.DefaultDeployConfiguration
-
- 1
-
-
-
- false
- false
- false
- false
- true
- 0.01
- 10
- true
- 1
- 25
-
- 1
- true
- false
- true
- valgrind
-
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
-
- 2
-
- deuchnord-hermes
-
- Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Jérôme/Dropbox/Git/Hermes/deuchnord-hermes/deuchnord-hermes.pro
-
- deuchnord-hermes.pro
- false
- false
-
- 3768
- false
- true
- false
- false
- true
-
- 1
-
-
-
- ProjectExplorer.Project.TargetCount
- 1
-
-
- ProjectExplorer.Project.Updater.EnvironmentId
- {60f16766-9e87-40cf-8f8f-b733441f2614}
-
-
- ProjectExplorer.Project.Updater.FileVersion
- 15
-
-
+
+
+
+
+
+ ProjectExplorer.Project.ActiveTarget
+ 0
+
+
+ ProjectExplorer.Project.EditorSettings
+
+ true
+ false
+ true
+
+ Cpp
+
+ CppGlobal
+
+
+
+ QmlJS
+
+ QmlJSGlobal
+
+
+ 2
+ UTF-8
+ false
+ 4
+ false
+ true
+ 1
+ true
+ 0
+ true
+ 0
+ 8
+ true
+ 1
+ true
+ true
+ true
+ false
+
+
+
+ ProjectExplorer.Project.PluginSettings
+
+
+
+ ProjectExplorer.Project.Target.0
+
+ Desktop
+ Desktop
+ {8a6bac83-397a-433b-b12b-aaf345693483}
+ 1
+ 0
+ 0
+
+ /home/jerome/Dropbox/Git/Hermes/build-deuchnord-hermes-Desktop-Debug
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ false
+ true
+
+ false
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ -w
+ -r
+
+ false
+
+
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ -w
+ -r
+
+ true
+ clean
+
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Debug
+
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+ true
+
+
+ /home/jerome/Dropbox/Git/Hermes/build-deuchnord-hermes-Desktop-Release
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ false
+ true
+
+ false
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ -w
+ -r
+
+ false
+
+
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ -w
+ -r
+
+ true
+ clean
+
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Release
+
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ true
+
+ 2
+
+
+ 0
+ Deploy
+
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+ Deploy locally
+
+ ProjectExplorer.DefaultDeployConfiguration
+
+ 1
+
+
+
+ false
+ false
+ false
+ false
+ true
+ 0.01
+ 10
+ true
+ 1
+ 25
+
+ 1
+ true
+ false
+ true
+ valgrind
+
+ 0
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 10
+ 11
+ 12
+ 13
+ 14
+
+ 2
+
+ deuchnord-hermes
+
+ Qt4ProjectManager.Qt4RunConfiguration:/home/jerome/Dropbox/Git/Hermes/deuchnord-hermes/deuchnord-hermes.pro
+
+ deuchnord-hermes.pro
+ false
+ false
+
+ 3768
+ true
+ false
+ false
+ false
+ true
+
+ 1
+
+
+
+ ProjectExplorer.Project.TargetCount
+ 1
+
+
+ ProjectExplorer.Project.Updater.EnvironmentId
+ {44abd538-5b46-4276-b819-6072e04c10d4}
+
+
+ ProjectExplorer.Project.Updater.FileVersion
+ 15
+
+
diff --git a/gestionmagasinsdialog.cpp b/gestionmagasinsdialog.cpp
index 59a3f34..499d804 100644
--- a/gestionmagasinsdialog.cpp
+++ b/gestionmagasinsdialog.cpp
@@ -5,6 +5,7 @@
#include
#include
#include
+#include
GestionMagasinsDialog::GestionMagasinsDialog(QWidget *parent) :
QDialog(parent),
@@ -47,7 +48,23 @@ GestionMagasinsDialog::GestionMagasinsDialog(QWidget *parent) :
void GestionMagasinsDialog::on_btnAjoutMagasin_clicked()
{
- ui->listMagasins->addItem(QInputDialog::getText(this, "Ajouter un magasin", "Veuillez entrer le nom du nouveau magasin :"));
+ QString nom = QInputDialog::getText(this, "Ajouter un magasin", "Veuillez entrer le nom du nouveau magasin :");
+ if(nom != "")
+ {
+ int nb = ui->listMagasins->count();
+ bool alreadyHere = false;
+ for(int i = 0; i < nb; i++)
+ {
+ QString magasin = ui->listMagasins->item(i)->text();
+ if(magasin.toLower() == nom.toLower())
+ alreadyHere = true;
+ }
+
+ if(alreadyHere)
+ QMessageBox::warning(this, "Ajout impossible", "Le magasin est déjà présent dans la liste !");
+ else
+ ui->listMagasins->addItem(nom);
+ }
}
void GestionMagasinsDialog::on_btnSupprMagasin_clicked()
diff --git a/infosproduitdialog.cpp b/infosproduitdialog.cpp
index 2201e47..8ae203c 100644
--- a/infosproduitdialog.cpp
+++ b/infosproduitdialog.cpp
@@ -42,10 +42,6 @@ InfosProduitDialog::InfosProduitDialog(QWidget *parent, QWidget *mainWindow, QSt
node = node.nextSibling();
}
}
- else
- {
- QMessageBox::critical(this, "Erreur", "Impossible de récupérer la liste des magasins.\nLes avez-vous enregistrés ?");
- }
// Remplissage des données
ui->txtNom->setText(nomProduit);
@@ -123,7 +119,7 @@ void InfosProduitDialog::on_listFactures_itemDoubleClicked(QListWidgetItem *item
tempFile.open(QFile::WriteOnly);
tempFile.write(contentFile);
tempFile.close();
- QDesktopServices::openUrl(QUrl(tempFile.fileName()));
+ QDesktopServices::openUrl(QUrl("file:///"+tempFile.fileName()));
}
void InfosProduitDialog::on_btnSupprFacture_clicked()
@@ -172,7 +168,7 @@ void InfosProduitDialog::on_listGaranties_itemDoubleClicked(QListWidgetItem *ite
tempFile.open(QFile::WriteOnly);
tempFile.write(contentFile);
tempFile.close();
- QDesktopServices::openUrl(QUrl(tempFile.fileName()));
+ QDesktopServices::openUrl(QUrl("file:///"+tempFile.fileName()));
}
void InfosProduitDialog::on_btnSupprGarantie_clicked()
diff --git a/mainwindow.cpp b/mainwindow.cpp
index c69b69b..d0b4ee5 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -4,6 +4,7 @@
#include "aboutdialog.h"
#include "ui_mainwindow.h"
+#include
#include
#include
#include
@@ -18,6 +19,7 @@
#include
#include
#include
+#include
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
@@ -52,7 +54,11 @@ MainWindow::MainWindow(QWidget *parent) :
ajouterProduit(new ProduitItem(this, i.nomProduit, i.dateAchat, i.dateFinGarantie, i.image, i.indexMagasin, i.enSAV, i.factures, i.garanties));
}
- ui->actionSupprimerProduit->setEnabled(false);
+ if(ui->listeProduits->count() > 0)
+ ui->listeProduits->item(0)->setSelected(true);
+ else
+ ui->actionSupprimerProduit->setEnabled(false);
+
ui->statusBar->hide();
}
@@ -82,20 +88,73 @@ void MainWindow::searchProduit(QString search)
void MainWindow::on_actionNouveauProduit_triggered()
{
- ProduitItem *prod = new ProduitItem(this, "Nouveau produit", QDate::currentDate(), QDate::currentDate().addYears(1));
- prod->openDialog();
- ajouterProduit(prod);
+ QFile fichierMagasins(QDir::homePath()+"/.deuchnord-hermes/manufacturers.xml");
+ fichierMagasins.open(QFile::ReadOnly);
+ int nbMagasins = 0;
+
+ if(fichierMagasins.isOpen())
+ {
+ QString contenuFichier = fichierMagasins.readAll();
+ fichierMagasins.close();
+
+ QDomDocument dom;
+ dom.setContent(contenuFichier);
+ QDomElement root = dom.firstChildElement();
+ QDomElement manufacturer;
+ QDomNode node = root.firstChild();
+
+ while(!node.isNull())
+ {
+ manufacturer = node.toElement();
+ if(manufacturer.tagName() == "manufacturer")
+ nbMagasins++;
+
+ node = node.nextSibling();
+ }
+ }
+
+ if(nbMagasins == 0)
+ {
+ QMessageBox::critical(this, "Erreur", "Aucun magasin ne semble avoir été enregistré.\nVeuillez les enregistrer avant d'entrer vos produits.");
+ ui->actionGererMagasins->trigger();
+ }
+ else
+ {
+ ProduitItem *prod = new ProduitItem(this, "Nouveau produit", QDate::currentDate(), QDate::currentDate().addYears(1));
+ prod->openDialog(true);
+ QListWidgetItem* item = ajouterProduit(prod);
+ item->setSelected(true);
+ connect(prod, SIGNAL(deleteAsked()), SLOT(deleteAsked()));
+ ui->actionSupprimerProduit->setEnabled(true);
+ }
}
-void MainWindow::on_actionSupprimerProduit_triggered()
+void MainWindow::deleteAsked()
+{
+ on_actionSupprimerProduit_triggered(true);
+}
+
+void MainWindow::on_actionSupprimerProduit_triggered(bool dontAskConfirm)
{
if(ui->listeProduits->selectedItems().count() == 1)
{
QListWidgetItem *item = ui->listeProduits->selectedItems()[0];
- if(QMessageBox::question(this, "Supprimer le produit", "Êtes-vous sûr de vouloir supprimer ce produit ?\nCette action n'est pas réversible.", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
+
+ int answer;
+ if(!dontAskConfirm)
+ answer = QMessageBox::question(this, "Supprimer le produit", "Êtes-vous sûr de vouloir supprimer ce produit ?\nCette action n'est pas réversible.", QMessageBox::Yes | QMessageBox::No);
+ else
+ answer = QMessageBox::Yes;
+
+ if(answer == QMessageBox::Yes)
{
+ ui->listeProduits->setCurrentRow(ui->listeProduits->row(item));
ui->listeProduits->removeItemWidget(item);
+
delete item;
+
+ if(ui->listeProduits->count() == 0)
+ ui->actionSupprimerProduit->setEnabled(false);
}
}
}
@@ -107,7 +166,7 @@ void MainWindow::on_actionGererMagasins_triggered()
dialog->show();
}
-void MainWindow::ajouterProduit(ProduitItem *produit)
+QListWidgetItem* MainWindow::ajouterProduit(ProduitItem *produit)
{
QListWidgetItem *widgetItem = new QListWidgetItem();
widgetItem->setSizeHint(QSize(0, 128));
@@ -115,11 +174,8 @@ void MainWindow::ajouterProduit(ProduitItem *produit)
ui->listeProduits->setItemWidget(widgetItem, produit);
//ui->statusBar->showMessage(QString::number(ui->listeProduits->count())+" produits affichés.");
-}
-void MainWindow::on_listeProduits_currentRowChanged()
-{
- ui->actionSupprimerProduit->setEnabled(true);
+ return widgetItem;
}
void MainWindow::on_actionAPropos_triggered()
@@ -134,6 +190,11 @@ void MainWindow::on_actionAide_triggered()
QDesktopServices::openUrl(QUrl("http://hermes.deuchnord.tk/help/"));
}
+Ui::MainWindow *MainWindow::getUI()
+{
+ return ui;
+}
+
MainWindow::~MainWindow()
{
// Enregistrement de la configuration
diff --git a/mainwindow.h b/mainwindow.h
index 571cc19..9c808e5 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -17,20 +17,22 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(QWidget *parent = 0);
+ Ui::MainWindow *getUI();
~MainWindow();
public slots:
void searchProduit(QString search);
void on_actionNouveauProduit_triggered();
- void on_actionSupprimerProduit_triggered();
+ void on_actionSupprimerProduit_triggered(bool dontAskConfirm = true);
void on_actionGererMagasins_triggered();
- void on_listeProduits_currentRowChanged();
void on_actionAPropos_triggered();
void on_actionAide_triggered();
+ void deleteAsked();
+
private:
Ui::MainWindow *ui;
- void ajouterProduit(ProduitItem *produit);
+ QListWidgetItem *ajouterProduit(ProduitItem *produit);
QLineEdit *searchBox;
QString version;
};
diff --git a/mainwindow.ui b/mainwindow.ui
index b772f1b..5009368 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -6,8 +6,8 @@
0
0
- 707
- 471
+ 765
+ 610
@@ -29,8 +29,8 @@
0
0
- 707
- 21
+ 765
+ 25
@@ -84,9 +84,6 @@
-
- false
-
Supprimer le produit
diff --git a/produititem.cpp b/produititem.cpp
index bc01a71..4199b77 100644
--- a/produititem.cpp
+++ b/produititem.cpp
@@ -1,5 +1,6 @@
#include "produititem.h"
#include "ui_produititem.h"
+#include "mainwindow.h"
#include
@@ -40,12 +41,21 @@ ProduitItem::ProduitItem(QWidget *parent, QString nomProduit, QDate dateAchat, Q
ui->btnMoreInfo->setToolTip("Ouvre une fenêtre contenant toutes les informations\nsur votre "+nomProduit+".");
}
-void ProduitItem::on_btnMoreInfo_clicked()
+void ProduitItem::on_btnMoreInfo_clicked(bool deleteOnCancel)
{
InfosProduitDialog *winInfoProd = new InfosProduitDialog(this, this->parentWidget(), nomProduit, dateAchat, dateFinGarantie, image, indexMagasin, enSAV, factures, garanties);
winInfoProd->setModal(true);
winInfoProd->show();
+
+ // Si on annule et que deleteOnCancel est vrai, le signal deleteAsked() sera déclenché.
+ if(deleteOnCancel)
+ connect(winInfoProd, SIGNAL(rejected()), SLOT(winInfoProdCanceled()));
+}
+
+void ProduitItem::winInfoProdCanceled()
+{
+ emit deleteAsked();
}
// Accesseurs
@@ -135,9 +145,9 @@ void ProduitItem::updateDescription()
ui->infosProduit->setText(descriptionListe);
}
-void ProduitItem::openDialog()
+void ProduitItem::openDialog(bool deleteOnCancel)
{
- ui->btnMoreInfo->click();
+ on_btnMoreInfo_clicked(deleteOnCancel);
}
// Pour la sérialisation
diff --git a/produititem.h b/produititem.h
index b6aacf0..b1ccd59 100644
--- a/produititem.h
+++ b/produititem.h
@@ -53,13 +53,17 @@ public:
void setGaranties(QHash garanties);
void updateDescription();
- void openDialog();
+ void openDialog(bool deleteOnCancel = false);
// Destructeur
~ProduitItem();
public slots:
- void on_btnMoreInfo_clicked();
+ void on_btnMoreInfo_clicked(bool deleteOnCancel = false);
+ void winInfoProdCanceled();
+
+signals:
+ void deleteAsked();
private:
Ui::ProduitItem *ui;