File indexing completed on 2025-10-12 03:31:32
0001 /* 0002 File : FITSHeaderEditDialog.h 0003 Project : LabPlot 0004 Description : Dialog for listing/editing FITS header keywords 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2016-2017 Fabian Kristof <fkristofszabolcs@gmail.com> 0007 SPDX-FileCopyrightText: 2016-2019 Alexander Semke <alexander.semke@web.de> 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "FITSHeaderEditDialog.h" 0012 #include "backend/core/Settings.h" 0013 0014 #include <QDialogButtonBox> 0015 #include <QPushButton> 0016 #include <QVBoxLayout> 0017 #include <QWindow> 0018 0019 #include <KWindowConfig> 0020 0021 /*! \class FITSHeaderEditDialog 0022 * \brief Dialog class for editing FITS header units. 0023 * \since 2.4.0 0024 * \ingroup widgets 0025 */ 0026 FITSHeaderEditDialog::FITSHeaderEditDialog(QWidget* parent) 0027 : QDialog(parent) 0028 , m_headerEditWidget(new FITSHeaderEditWidget(this)) { 0029 auto* btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0030 auto* layout = new QVBoxLayout; 0031 0032 layout->addWidget(m_headerEditWidget); 0033 layout->addWidget(btnBox); 0034 0035 setLayout(layout); 0036 0037 m_okButton = btnBox->button(QDialogButtonBox::Ok); 0038 m_okButton->setText(i18n("&Save")); 0039 m_okButton->setEnabled(false); 0040 0041 connect(btnBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &FITSHeaderEditDialog::reject); 0042 connect(btnBox, &QDialogButtonBox::accepted, this, &FITSHeaderEditDialog::accept); 0043 connect(btnBox, &QDialogButtonBox::rejected, this, &FITSHeaderEditDialog::reject); 0044 0045 setWindowTitle(i18nc("@title:window", "FITS Metadata Editor")); 0046 setWindowIcon(QIcon::fromTheme(QStringLiteral("document-edit"))); 0047 0048 connect(m_okButton, &QPushButton::clicked, this, &FITSHeaderEditDialog::save); 0049 connect(m_headerEditWidget, &FITSHeaderEditWidget::changed, this, &FITSHeaderEditDialog::headersChanged); 0050 0051 setAttribute(Qt::WA_DeleteOnClose); 0052 0053 // restore saved settings if available 0054 create(); // ensure there's a window created 0055 KConfigGroup conf = Settings::group(QStringLiteral("FITSHeaderEditDialog")); 0056 if (conf.exists()) { 0057 KWindowConfig::restoreWindowSize(windowHandle(), conf); 0058 resize(windowHandle()->size()); // workaround for QTBUG-40584 0059 } else 0060 resize(QSize(300, 0).expandedTo(minimumSize())); 0061 } 0062 0063 /*! 0064 * \brief FITSHeaderEditDialog::~FITSHeaderEditDialog 0065 */ 0066 FITSHeaderEditDialog::~FITSHeaderEditDialog() { 0067 KConfigGroup conf = Settings::group(QStringLiteral("FITSHeaderEditDialog")); 0068 KWindowConfig::saveWindowSize(windowHandle(), conf); 0069 delete m_headerEditWidget; 0070 } 0071 0072 void FITSHeaderEditDialog::headersChanged(bool changed) { 0073 if (changed) { 0074 setWindowTitle(i18nc("@title:window", "FITS Metadata Editor [Changed]")); 0075 m_okButton->setEnabled(true); 0076 } else { 0077 setWindowTitle(i18nc("@title:window", "FITS Metadata Editor")); 0078 m_okButton->setEnabled(false); 0079 } 0080 } 0081 0082 /*! 0083 * \brief This slot is triggered when the Save button was clicked in the ui. 0084 */ 0085 void FITSHeaderEditDialog::save() { 0086 m_saved = m_headerEditWidget->save(); 0087 } 0088 0089 /*! 0090 * \brief Returns whether there were changes saved. 0091 * \return 0092 */ 0093 bool FITSHeaderEditDialog::saved() const { 0094 return m_saved; 0095 }