File indexing completed on 2024-05-12 15:28:19

0001 /***************************************************************************
0002 File                 : FITSHeaderEditWidget.h
0003 Project              : LabPlot
0004 Description          : Widget for listing/editing FITS header keywords
0005 --------------------------------------------------------------------
0006 Copyright            : (C) 2016 by Fabian Kristof (fkristofszabolcs@gmail.com)
0007 ***************************************************************************/
0008 
0009 /***************************************************************************
0010 *                                                                         *
0011 *  This program is free software; you can redistribute it and/or modify   *
0012 *  it under the terms of the GNU General Public License as published by   *
0013 *  the Free Software Foundation; either version 2 of the License, or      *
0014 *  (at your option) any later version.                                    *
0015 *                                                                         *
0016 *  This program is distributed in the hope that it will be useful,        *
0017 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0018 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0019 *  GNU General Public License for more details.                           *
0020 *                                                                         *
0021 *   You should have received a copy of the GNU General Public License     *
0022 *   along with this program; if not, write to the Free Software           *
0023 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0024 *   Boston, MA  02110-1301  USA                                           *
0025 *                                                                         *
0026 ***************************************************************************/
0027 #ifndef FITSHEADEREDITWIDGET_H
0028 #define FITSHEADEREDITWIDGET_H
0029 
0030 #include <QWidget>
0031 #include "backend/datasources/filters/FITSFilter.h"
0032 
0033 namespace Ui {
0034     class FITSHeaderEditWidget;
0035 }
0036 
0037 class FITSHeaderEditWidget : public QWidget {
0038     Q_OBJECT
0039 
0040 public:
0041     explicit FITSHeaderEditWidget(QWidget *parent = nullptr);
0042     ~FITSHeaderEditWidget() override;
0043 
0044 private:
0045     Ui::FITSHeaderEditWidget* ui;
0046     QAction* m_actionRemoveKeyword{nullptr};
0047     QAction* m_actionAddKeyword{nullptr};
0048     QAction* m_actionAddmodifyUnit{nullptr};
0049     QAction* m_actionRemoveExtension{nullptr};
0050 
0051     QMenu* m_keywordActionsMenu{nullptr};
0052     QMenu* m_extensionActionsMenu{nullptr};
0053 
0054     struct HeaderUpdate {
0055         QList<FITSFilter::Keyword> newKeywords;
0056         QVector<FITSFilter::Keyword> updatedKeywords;
0057         QList<FITSFilter::Keyword> removedKeywords;
0058     };
0059 
0060     struct ExtensionData {
0061         HeaderUpdate updates;
0062         QList<FITSFilter::Keyword> keywords;
0063     };
0064 
0065     QMap<QString, ExtensionData> m_extensionData;
0066     QStringList m_removedExtensions;
0067     QString m_seletedExtension;
0068 
0069     FITSFilter* m_fitsFilter;
0070 
0071     bool m_initializingTable{false};
0072 
0073     void initActions();
0074     void initContextMenus();
0075     void connectActions();
0076     void fillTable();
0077     QList<QString> mandatoryKeywords() const;
0078     bool eventFilter(QObject*, QEvent*) override;
0079 
0080 public slots:
0081     bool save();
0082 
0083 private slots:
0084     void openFile();
0085 
0086     void fillTableSlot(QTreeWidgetItem* item, int col);
0087     void updateKeyword(QTableWidgetItem*);
0088 
0089     void removeKeyword();
0090     void removeExtension();
0091     void addKeyword();
0092     void addModifyKeywordUnit();
0093     void closeFile();
0094     void enableButtonCloseFile(QTreeWidgetItem *, int);
0095     void enableButtonAddUnit();
0096 signals:
0097     void changed(bool);
0098 };
0099 
0100 #endif // FITSHEADEREDITWIDGET_H