From 6ad6e5a1f9da9a5387021a68c996fc9cabbf2e53 Mon Sep 17 00:00:00 2001 From: Adarsh Balasubramanian Date: Thu, 27 Sep 2018 16:42:18 -0400 Subject: [PATCH] Making use of qtgui's backgroundfileformat Signed-off-by: Adarsh Balasubramanian --- avogadro/qtgui/backgroundfileformat.cpp | 3 +- .../qtplugins/customelements/CMakeLists.txt | 2 +- .../customelements/backgroundfileformat.cpp | 86 -------------- .../customelements/backgroundfileformat.h | 107 ------------------ .../customelements/customelements.cpp | 7 +- .../qtplugins/customelements/customelements.h | 4 +- 6 files changed, 11 insertions(+), 198 deletions(-) delete mode 100644 avogadro/qtplugins/customelements/backgroundfileformat.cpp delete mode 100644 avogadro/qtplugins/customelements/backgroundfileformat.h diff --git a/avogadro/qtgui/backgroundfileformat.cpp b/avogadro/qtgui/backgroundfileformat.cpp index d6c6a91c54..f571895a10 100644 --- a/avogadro/qtgui/backgroundfileformat.cpp +++ b/avogadro/qtgui/backgroundfileformat.cpp @@ -25,7 +25,8 @@ namespace QtGui { BackgroundFileFormat::BackgroundFileFormat(Io::FileFormat* format, QObject* aparent) : QObject(aparent), m_format(format), m_molecule(nullptr), m_success(false) -{} +{ +} BackgroundFileFormat::~BackgroundFileFormat() { diff --git a/avogadro/qtplugins/customelements/CMakeLists.txt b/avogadro/qtplugins/customelements/CMakeLists.txt index fd0bc3a8d5..c405001fd7 100644 --- a/avogadro/qtplugins/customelements/CMakeLists.txt +++ b/avogadro/qtplugins/customelements/CMakeLists.txt @@ -3,5 +3,5 @@ avogadro_plugin(CustomElements ExtensionPlugin customelements.h CustomElements - "customelements.cpp;backgroundfileformat.cpp" + "customelements.cpp" ) diff --git a/avogadro/qtplugins/customelements/backgroundfileformat.cpp b/avogadro/qtplugins/customelements/backgroundfileformat.cpp deleted file mode 100644 index 7885869676..0000000000 --- a/avogadro/qtplugins/customelements/backgroundfileformat.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/****************************************************************************** - - This source file is part of the Avogadro project. - - Copyright 2013 Kitware, Inc. - - This source code is released under the New BSD License, (the "License"). - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -******************************************************************************/ - -#include "backgroundfileformat.h" - -#include - -namespace Avogadro { - -BackgroundFileFormat::BackgroundFileFormat(Io::FileFormat* format, - QObject* aparent) - : QObject(aparent) - , m_format(format) - , m_molecule(nullptr) - , m_success(false) -{} - -BackgroundFileFormat::~BackgroundFileFormat() -{ - delete m_format; -} - -void BackgroundFileFormat::read() -{ - m_success = false; - m_error.clear(); - - if (!m_molecule) - m_error = tr("No molecule set in BackgroundFileFormat!"); - - if (!m_format) - m_error = tr("No Io::FileFormat set in BackgroundFileFormat!"); - - if (m_fileName.isEmpty()) - m_error = tr("No file name set in BackgroundFileFormat!"); - - if (m_error.isEmpty()) { - m_success = - m_format->readFile(m_fileName.toLocal8Bit().data(), *m_molecule); - - if (!m_success) - m_error = QString::fromStdString(m_format->error()); - } - - emit finished(); -} - -void BackgroundFileFormat::write() -{ - m_success = false; - m_error.clear(); - - if (!m_molecule) - m_error = tr("No molecule set in BackgroundFileFormat!"); - - if (!m_format) - m_error = tr("No Io::FileFormat set in BackgroundFileFormat!"); - - if (m_fileName.isEmpty()) - m_error = tr("No file name set in BackgroundFileFormat!"); - - if (m_error.isEmpty()) { - m_success = - m_format->writeFile(m_fileName.toLocal8Bit().data(), *m_molecule); - - if (!m_success) - m_error = QString::fromStdString(m_format->error()); - } - - emit finished(); -} - -} // namespace Avogadro diff --git a/avogadro/qtplugins/customelements/backgroundfileformat.h b/avogadro/qtplugins/customelements/backgroundfileformat.h deleted file mode 100644 index b54cf31515..0000000000 --- a/avogadro/qtplugins/customelements/backgroundfileformat.h +++ /dev/null @@ -1,107 +0,0 @@ -/****************************************************************************** - - This source file is part of the Avogadro project. - - Copyright 2013 Kitware, Inc. - - This source code is released under the New BSD License, (the "License"). - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -******************************************************************************/ - -#ifndef AVOGADRO_BACKGROUNDFILEFORMAT_H -#define AVOGADRO_BACKGROUNDFILEFORMAT_H - -#include -#include - -namespace Avogadro { - -namespace Core { -class Molecule; -} - -namespace Io { -class FileFormat; -} - -/** - * @brief The BackgroundFileFormat class provides a thin QObject wrapper around - * an instance of Io::FileFormat. - */ -class BackgroundFileFormat : public QObject -{ - Q_OBJECT -public: - /** - * This class takes ownership of @a format and will delete it when destructed. - */ - explicit BackgroundFileFormat(Io::FileFormat* format, QObject* aparent = 0); - ~BackgroundFileFormat(); - - /** - * The molecule instance to read/write. - * @{ - */ - void setMolecule(Core::Molecule* mol) { m_molecule = mol; } - Core::Molecule* molecule() const { return m_molecule; } - /**@}*/ - - /** - * The name of the file to read/write. - * @{ - */ - void setFileName(const QString& filename) { m_fileName = filename; } - QString fileName() const { return m_fileName; } - /**@}*/ - - /** - * The Io::FileFormat to use. - */ - Io::FileFormat* fileFormat() const { return m_format; } - - /** - * @return True if the operation was successful. - */ - bool success() const { return m_success; } - - /** - * @return An error string, set if success() is false. - */ - QString error() const { return m_error; } - -signals: - - /** - * Emitted when a call to read or write is called. - */ - void finished(); - -public slots: - - /** - * Use the fileFormat() to read fileName() into molecule(). - */ - void read(); - - /** - * Use the fileFormat() to write fileName() from molecule(). - */ - void write(); - -private: - Io::FileFormat* m_format; - Core::Molecule* m_molecule; - QString m_fileName; - QString m_error; - bool m_success; -}; - -} // namespace Avogadro - -#endif // AVOGADRO_BACKGROUNDFILEFORMAT_H diff --git a/avogadro/qtplugins/customelements/customelements.cpp b/avogadro/qtplugins/customelements/customelements.cpp index a3df04a55a..64149368e3 100644 --- a/avogadro/qtplugins/customelements/customelements.cpp +++ b/avogadro/qtplugins/customelements/customelements.cpp @@ -15,8 +15,8 @@ ******************************************************************************/ #include "customelements.h" -#include "backgroundfileformat.h" +#include #include #include #include @@ -28,6 +28,7 @@ #include using Avogadro::QtGui::Molecule; +using Avogadro::QtGui::BackgroundFileFormat; namespace Avogadro { namespace QtPlugins { @@ -47,7 +48,9 @@ CustomElements::CustomElements(QObject* parent_) updateReassignAction(); } -CustomElements::~CustomElements() {} +CustomElements::~CustomElements() +{ +} QString CustomElements::description() const { diff --git a/avogadro/qtplugins/customelements/customelements.h b/avogadro/qtplugins/customelements/customelements.h index 23ae54f857..27cd029528 100644 --- a/avogadro/qtplugins/customelements/customelements.h +++ b/avogadro/qtplugins/customelements/customelements.h @@ -24,7 +24,9 @@ class QThread; namespace Avogadro { +namespace QtGui { class BackgroundFileFormat; +} namespace QtPlugins { @@ -57,7 +59,7 @@ private slots: QAction* m_reassignUsingTool; QAction* m_reassignFromFile; QThread* m_fileReadThread; - BackgroundFileFormat* m_threadedReader; + QtGui::BackgroundFileFormat* m_threadedReader; QtGui::Molecule* m_fileReadMolecule; QProgressDialog* m_progressDialog;