Debian Codegraph @

avogadro/qtgui/backgroundfileformat.h

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 #ifndef AVOGADRO_QTGUI_BACKGROUNDFILEFORMAT_H
7 #define AVOGADRO_QTGUI_BACKGROUNDFILEFORMAT_H
8
9 #include "avogadroqtguiexport.h"
10
11 #include <QtCore/QObject>
12 #include <QtCore/QString>
13
14 namespace Avogadro {
15
16 namespace Core {
17 class Molecule;
18 }
19
20 namespace Io {
21 class FileFormat;
22 }
23
24 namespace QtGui {
25
26 /**
27 * @brief The BackgroundFileFormat class provides a thin QObject wrapper around
28 * an instance of Io::FileFormat.
29 */
30 class AVOGADROQTGUI_EXPORT BackgroundFileFormat : public QObject
31 {
32 Q_OBJECT
33 public:
34 /**
35 * This class takes ownership of @a format and will delete it when destructed.
36 */
37 explicit BackgroundFileFormat(Io::FileFormat* format,
38 QObject* parent = nullptr);
39 ~BackgroundFileFormat() override;
40
41 /**
42 * The molecule instance to read/write.
43 * @{
44 */
45 void setMolecule(Core::Molecule* mol) { m_molecule = mol; }
46 Core::Molecule* molecule() const { return m_molecule; }
47 /**@}*/
48
49 /**
50 * The name of the file to read/write.
51 * @{
52 */
53 void setFileName(const QString& filename) { m_fileName = filename; }
54 QString fileName() const { return m_fileName; }
55 /**@}*/
56
57 /**
58 * The Io::FileFormat to use.
59 */
60 Io::FileFormat* fileFormat() const { return m_format; }
61
62 /**
63 * @return True if the operation was successful.
64 */
65 bool success() const { return m_success; }
66
67 /**
68 * @return An error string, set if success() is false.
69 */
70 QString error() const { return m_error; }
71
72 signals:
73
74 /**
75 * Emitted when a call to read or write is called.
76 */
77 void finished();
78
79 public slots:
80
81 /**
82 * Use the fileFormat() to read fileName() into molecule().
83 */
84 void read();
85
86 /**
87 * Use the fileFormat() to write fileName() from molecule().
88 */
89 void write();
90
91 private:
92 Io::FileFormat* m_format;
93 Core::Molecule* m_molecule;
94 QString m_fileName;
95 QString m_error;
96 bool m_success;
97 };
98
99 } // namespace QtGui
100 } // namespace Avogadro
101
102 #endif // AVOGADRO_BACKGROUNDFILEFORMAT_H