Your warranties manager
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

80 lines
2.1 KiB

  1. #include "manufacturersmanager.h"
  2. #include <QSettings>
  3. #include <QFile>
  4. #include <QDomDocument>
  5. #include <QDomElement>
  6. #include <QDomNode>
  7. ManufacturersManager::ManufacturersManager()
  8. {
  9. QSettings *settings = new QSettings("Deuchnord", "Hermes");
  10. QFile fichierMagasins(settings->value("placeSave").toString()+"/deuchnord-hermes/manufacturers.xml");
  11. fichierMagasins.open(QFile::ReadOnly);
  12. if(fichierMagasins.isOpen())
  13. {
  14. QString contenuFichier = fichierMagasins.readAll();
  15. fichierMagasins.close();
  16. QDomDocument dom;
  17. dom.setContent(contenuFichier);
  18. QDomElement root = dom.firstChildElement();
  19. QDomElement manufacturer;
  20. QDomNode node = root.firstChild();
  21. while(!node.isNull())
  22. {
  23. manufacturer = node.toElement();
  24. if(manufacturer.tagName() == "manufacturer")
  25. manufacturers.append(manufacturer.firstChild().toText().data());
  26. node = node.nextSibling();
  27. }
  28. }
  29. }
  30. void ManufacturersManager::addManufacturer(QString manufacturer) {
  31. manufacturers.append(manufacturer);
  32. }
  33. QList<QString> ManufacturersManager::getManufacturers() {
  34. return manufacturers;
  35. }
  36. void ManufacturersManager::deleteManufacturer(int manufacturerToDelete) {
  37. manufacturers.removeAt(manufacturerToDelete);
  38. }
  39. void ManufacturersManager::save() {
  40. QDomDocument dom("manufacturers");
  41. QDomElement rootElement = dom.createElement("manufacturers");
  42. dom.appendChild(rootElement);
  43. for(QString manufacturer : manufacturers) {
  44. QDomElement domManufacturer = dom.createElement("manufacturer");
  45. rootElement.appendChild(domManufacturer);
  46. QDomText textManufacturer = dom.createTextNode(manufacturer);
  47. domManufacturer.appendChild(textManufacturer);
  48. }
  49. QSettings *settings = new QSettings("Deuchnord", "Hermes");
  50. QFile fichierMagasins(settings->value("placeSave").toString()+"/deuchnord-hermes/manufacturers.xml");
  51. if(fichierMagasins.open(QFile::WriteOnly)) {
  52. fichierMagasins.write(dom.toString().toUtf8());
  53. fichierMagasins.close();
  54. }
  55. }