File indexing completed on 2024-05-12 15:27:46
0001 /*************************************************************************** 0002 File : DatasetMetadataManagerDialog.cpp 0003 Project : LabPlot 0004 Description : Dialog for managing a metadata file of a dataset 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2019 Ferencz Kovacs (kferike98@gmail.com) 0007 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 0029 #include "src/kdefrontend/datasources/DatasetMetadataManagerDialog.h" 0030 #include "src/kdefrontend/datasources/DatasetMetadataManagerWidget.h" 0031 0032 #include <KConfigGroup> 0033 #include <KLocalizedString> 0034 #include <KSharedConfig> 0035 #include <KWindowConfig> 0036 #include <QDialogButtonBox> 0037 #include <QWindow> 0038 #include <QPushButton> 0039 0040 /*! 0041 \class DatasetMetadataManagerDialog 0042 \brief Dialog for adding a new dataset to LabPlot's current collection. Embeds \c DatasetMetadataManagerWidget and provides the standard buttons. 0043 0044 \ingroup kdefrontend 0045 */ 0046 DatasetMetadataManagerDialog::DatasetMetadataManagerDialog(QWidget* parent, const QMap< QString, QMap<QString, QMap<QString, QVector<QString>>>>& datasetMap) : QDialog(parent), 0047 m_mainWidget(new DatasetMetadataManagerWidget(this, datasetMap)), 0048 m_buttonBox(nullptr), 0049 m_okButton(nullptr) { 0050 connect(m_mainWidget, &DatasetMetadataManagerWidget::checkOk, this, &DatasetMetadataManagerDialog::checkOkButton); 0051 0052 setWindowTitle(i18nc("@title:window", "Dataset metadata manager")); 0053 0054 m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0055 m_okButton = m_buttonBox->button(QDialogButtonBox::Ok); 0056 m_okButton->setEnabled(false); 0057 0058 auto* layout = new QVBoxLayout(this); 0059 layout->addWidget(m_mainWidget); 0060 layout->addWidget(m_buttonBox); 0061 0062 connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0063 connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0064 0065 //restore saved settings if available 0066 create(); // ensure there's a window created 0067 KConfigGroup conf(KSharedConfig::openConfig(), "DatasetMetadataManagerDialog"); 0068 if (conf.exists()) { 0069 KWindowConfig::restoreWindowSize(windowHandle(), conf); 0070 resize(windowHandle()->size()); // workaround for QTBUG-40584 0071 } else { 0072 resize(QSize(0, 0).expandedTo(minimumSize())); 0073 } 0074 0075 checkOkButton(); 0076 } 0077 0078 DatasetMetadataManagerDialog::~DatasetMetadataManagerDialog() { 0079 //save current settings 0080 KConfigGroup conf(KSharedConfig::openConfig(), "DatasetMetadataManagerDialog"); 0081 KWindowConfig::saveWindowSize(windowHandle(), conf); 0082 } 0083 0084 /** 0085 * @brief Checks whether the OK button of the dialog can be pressed or not 0086 */ 0087 void DatasetMetadataManagerDialog::checkOkButton() { 0088 bool enable = m_mainWidget->checkDataValidity(); 0089 m_okButton->setEnabled(enable); 0090 } 0091 0092 /** 0093 * @brief Triggers updating the metadata file containing the categories, subcategories and datasets. 0094 * @param fileName the name of the metadata file (path) 0095 */ 0096 void DatasetMetadataManagerDialog::updateDocument(const QString& fileName) { 0097 m_mainWidget->updateDocument(fileName); 0098 } 0099 0100 /** 0101 * @brief returns the path to the new metadata file of the new dataset. 0102 */ 0103 QString DatasetMetadataManagerDialog::getMetadataFilePath() const { 0104 return m_mainWidget->getMetadataFilePath(); 0105 } 0106 0107 /** 0108 * @brief Sets the collection name in the DatasetMetadataManagerWidget 0109 */ 0110 void DatasetMetadataManagerDialog::setCollection(const QString& collection) { 0111 m_mainWidget->setCollection(collection); 0112 } 0113 0114 /** 0115 * @brief Sets the category name in the DatasetMetadataManagerWidget 0116 */ 0117 void DatasetMetadataManagerDialog::setCategory(const QString& category) { 0118 m_mainWidget->setCategory(category); 0119 } 0120 0121 /** 0122 * @brief Sets the subcategory name in the DatasetMetadataManagerWidget 0123 */ 0124 void DatasetMetadataManagerDialog::setSubcategory(const QString& subcategory) { 0125 m_mainWidget->setSubcategory(subcategory); 0126 } 0127 0128 /** 0129 * @brief Sets the short name of the dataset in the DatasetMetadataManagerWidget 0130 */ 0131 void DatasetMetadataManagerDialog::setShortName(const QString& name) { 0132 m_mainWidget->setShortName(name); 0133 } 0134 0135 /** 0136 * @brief Sets the full name of the dataset in the DatasetMetadataManagerWidget 0137 */ 0138 void DatasetMetadataManagerDialog::setFullName(const QString& name) { 0139 m_mainWidget->setFullName(name); 0140 } 0141 0142 /** 0143 * @brief Sets the text of the description in the DatasetMetadataManagerWidget 0144 */ 0145 void DatasetMetadataManagerDialog::setDescription(const QString& description) { 0146 m_mainWidget->setDescription(description); 0147 } 0148 0149 /** 0150 * @brief Sets the download url in the DatasetMetadataManagerWidget 0151 */ 0152 void DatasetMetadataManagerDialog::setURL(const QString& url) { 0153 m_mainWidget->setURL(url); 0154 }