Debian Codegraph @

avogadro/qtgui/backgroundfileformat.cpp

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #include "backgroundfileformat.h"
7
8 #include <avogadro/io/fileformat.h>
9
10 namespace Avogadro::QtGui {
11
12 BackgroundFileFormat::BackgroundFileFormat(Io::FileFormat* format,
13 QObject* parent)
14 : QObject(parent), m_format(format), m_molecule(nullptr), m_success(false)
15 {
16 }
17
18 BackgroundFileFormat::~BackgroundFileFormat()
19 {
20 delete m_format;
21 }
22
23 void BackgroundFileFormat::read()
24 {
25 m_success = false;
26 m_error.clear();
27
28 if (!m_molecule)
29 m_error = tr("No molecule set in BackgroundFileFormat!");
30
31 if (!m_format)
32 m_error = tr("No Io::FileFormat set in BackgroundFileFormat!");
33
34 if (m_fileName.isEmpty())
35 m_error = tr("No file name set in BackgroundFileFormat!");
36
37 if (m_error.isEmpty()) {
38 m_success =
39 m_format->readFile(m_fileName.toLocal8Bit().data(), *m_molecule);
40
41 if (!m_success)
42 m_error = QString::fromStdString(m_format->error());
43 }
44
45 emit finished();
46 }
47
48 void BackgroundFileFormat::write()
49 {
50 m_success = false;
51 m_error.clear();
52
53 if (!m_molecule)
54 m_error = tr("No molecule set in BackgroundFileFormat!");
55
56 if (!m_format)
57 m_error = tr("No Io::FileFormat set in BackgroundFileFormat!");
58
59 if (m_fileName.isEmpty())
60 m_error = tr("No file name set in BackgroundFileFormat!");
61
62 if (m_error.isEmpty()) {
63 m_success =
64 m_format->writeFile(m_fileName.toLocal8Bit().data(), *m_molecule);
65
66 if (!m_success)
67 m_error = QString::fromStdString(m_format->error());
68 }
69
70 emit finished();
71 }
72
73 } // namespace Avogadro::QtGui