File indexing completed on 2025-10-26 03:35:30
0001 /* 0002 File : DatasetMetadataManagerDialog.cpp 0003 Project : LabPlot 0004 Description : Dialog for managing a metadata file of a dataset 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2019 Ferencz Kovacs <kferike98@gmail.com> 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "src/kdefrontend/datasources/DatasetMetadataManagerDialog.h" 0011 #include "backend/core/Settings.h" 0012 #include "src/kdefrontend/datasources/DatasetMetadataManagerWidget.h" 0013 0014 #include <KConfigGroup> 0015 #include <KLocalizedString> 0016 0017 #include <KWindowConfig> 0018 #include <QDialogButtonBox> 0019 #include <QPushButton> 0020 #include <QWindow> 0021 0022 /*! 0023 \class DatasetMetadataManagerDialog 0024 \brief Dialog for adding a new dataset to LabPlot's current collection. Embeds \c DatasetMetadataManagerWidget and provides the standard buttons. 0025 0026 \ingroup kdefrontend 0027 */ 0028 DatasetMetadataManagerDialog::DatasetMetadataManagerDialog(QWidget* parent, const QMap<QString, QMap<QString, QMap<QString, QVector<QString>>>>& datasetMap) 0029 : QDialog(parent) 0030 , m_mainWidget(new DatasetMetadataManagerWidget(this, datasetMap)) 0031 , m_buttonBox(nullptr) 0032 , m_okButton(nullptr) { 0033 connect(m_mainWidget, &DatasetMetadataManagerWidget::checkOk, this, &DatasetMetadataManagerDialog::checkOkButton); 0034 0035 setWindowTitle(i18nc("@title:window", "Dataset metadata manager")); 0036 0037 m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0038 m_okButton = m_buttonBox->button(QDialogButtonBox::Ok); 0039 m_okButton->setEnabled(false); 0040 0041 auto* layout = new QVBoxLayout(this); 0042 layout->addWidget(m_mainWidget); 0043 layout->addWidget(m_buttonBox); 0044 0045 connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0046 connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0047 0048 // restore saved settings if available 0049 create(); // ensure there's a window created 0050 KConfigGroup conf = Settings::group(QStringLiteral("DatasetMetadataManagerDialog")); 0051 if (conf.exists()) { 0052 KWindowConfig::restoreWindowSize(windowHandle(), conf); 0053 resize(windowHandle()->size()); // workaround for QTBUG-40584 0054 } else { 0055 resize(QSize(0, 0).expandedTo(minimumSize())); 0056 } 0057 0058 checkOkButton(); 0059 } 0060 0061 DatasetMetadataManagerDialog::~DatasetMetadataManagerDialog() { 0062 // save current settings 0063 KConfigGroup conf = Settings::group(QStringLiteral("DatasetMetadataManagerDialog")); 0064 KWindowConfig::saveWindowSize(windowHandle(), conf); 0065 } 0066 0067 /** 0068 * @brief Checks whether the OK button of the dialog can be pressed or not 0069 */ 0070 void DatasetMetadataManagerDialog::checkOkButton() { 0071 bool enable = m_mainWidget->checkDataValidity(); 0072 m_okButton->setEnabled(enable); 0073 } 0074 0075 /** 0076 * @brief Triggers updating the metadata file containing the categories, subcategories and datasets. 0077 * @param fileName the name of the metadata file (path) 0078 */ 0079 void DatasetMetadataManagerDialog::updateDocument(const QString& fileName) { 0080 m_mainWidget->updateDocument(fileName); 0081 } 0082 0083 /** 0084 * @brief returns the path to the new metadata file of the new dataset. 0085 */ 0086 QString DatasetMetadataManagerDialog::getMetadataFilePath() const { 0087 return m_mainWidget->getMetadataFilePath(); 0088 } 0089 0090 /** 0091 * @brief Sets the collection name in the DatasetMetadataManagerWidget 0092 */ 0093 void DatasetMetadataManagerDialog::setCollection(const QString& collection) { 0094 m_mainWidget->setCollection(collection); 0095 } 0096 0097 /** 0098 * @brief Sets the category name in the DatasetMetadataManagerWidget 0099 */ 0100 void DatasetMetadataManagerDialog::setCategory(const QString& category) { 0101 m_mainWidget->setCategory(category); 0102 } 0103 0104 /** 0105 * @brief Sets the subcategory name in the DatasetMetadataManagerWidget 0106 */ 0107 void DatasetMetadataManagerDialog::setSubcategory(const QString& subcategory) { 0108 m_mainWidget->setSubcategory(subcategory); 0109 } 0110 0111 /** 0112 * @brief Sets the short name of the dataset in the DatasetMetadataManagerWidget 0113 */ 0114 void DatasetMetadataManagerDialog::setShortName(const QString& name) { 0115 m_mainWidget->setShortName(name); 0116 } 0117 0118 /** 0119 * @brief Sets the full name of the dataset in the DatasetMetadataManagerWidget 0120 */ 0121 void DatasetMetadataManagerDialog::setFullName(const QString& name) { 0122 m_mainWidget->setFullName(name); 0123 } 0124 0125 /** 0126 * @brief Sets the text of the description in the DatasetMetadataManagerWidget 0127 */ 0128 void DatasetMetadataManagerDialog::setDescription(const QString& description) { 0129 m_mainWidget->setDescription(description); 0130 } 0131 0132 /** 0133 * @brief Sets the download url in the DatasetMetadataManagerWidget 0134 */ 0135 void DatasetMetadataManagerDialog::setURL(const QString& url) { 0136 m_mainWidget->setURL(url); 0137 }