generatorfileoutput.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <QTextStream>
  2. #include <QMessageBox>
  3. #include <QDebug>
  4. #include <QFileInfo>
  5. #include "defines.h"
  6. #include "generatorfileoutput.h"
  7. GeneratorFileOutput::GeneratorFileOutput(const QString& outputFile)
  8. : m_outputFile(0)
  9. {
  10. setOutput(outputFile);
  11. }
  12. GeneratorFileOutput::~GeneratorFileOutput()
  13. {
  14. if (m_outputFile)
  15. {
  16. m_outputFile->close();
  17. }
  18. delete m_outputFile;
  19. }
  20. bool GeneratorFileOutput::setOutput(const QString &outputFile)
  21. {
  22. // Check if the new file is the same as the old one
  23. if (!m_outputFile || QFileInfo(outputFile) != QFileInfo(*m_outputFile))
  24. {
  25. if (m_outputFile)
  26. {
  27. m_outputFile->close();
  28. }
  29. delete m_outputFile;
  30. m_outputFile = 0;
  31. m_outputFile = new QFile(outputFile);
  32. if (!m_outputFile->open(QIODevice::WriteOnly | QIODevice::Text))
  33. {
  34. return false;
  35. }
  36. else
  37. {
  38. return true;
  39. }
  40. }
  41. else
  42. {
  43. return true;
  44. }
  45. }
  46. void GeneratorFileOutput::printOutput(const QString &message)
  47. {
  48. if (m_outputFile)
  49. {
  50. qDebug() << message;
  51. QTextStream(m_outputFile) << message << "\n";
  52. }
  53. emit GeneratorOutputView::message(message);
  54. }