Your warranties manager
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

manufacturersmanager.cpp 2.1 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }