File indexing completed on 2024-11-10 03:32:21

0001 /*
0002     File                 : ImportDatasetWidget.h
0003     Project              : LabPlot
0004     Description          : import online dataset widget
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2019 Kovacs Ferencz <kferike98@gmail.com>
0007     SPDX-FileCopyrightText: 2019-2023 Alexander Semke <alexander.semke@web.de>
0008 
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 #ifndef IMPORTDATASETWIDGET_H
0013 #define IMPORTDATASETWIDGET_H
0014 
0015 #include "QMap"
0016 #include "ui_importdatasetwidget.h"
0017 #include <QJsonArray>
0018 #include <QJsonObject>
0019 
0020 class DatasetHandler;
0021 class DatasetModel;
0022 class QCompleter;
0023 class QNetworkAccessManager;
0024 class QNetworkReply;
0025 
0026 typedef QMap<QString, QMap<QString, QMap<QString, QVector<QString>>>> DatasetsMap;
0027 
0028 class ImportDatasetWidget : public QWidget {
0029     Q_OBJECT
0030 
0031 public:
0032     explicit ImportDatasetWidget(QWidget* parent);
0033     ~ImportDatasetWidget() override;
0034 
0035     QString getSelectedDataset() const;
0036     void import(DatasetHandler*);
0037     const DatasetsMap& getDatasetsMap();
0038     void setCollection(const QString&);
0039     void setCategory(const QString&);
0040     void setSubcategory(const QString&);
0041     void setDataset(const QString&);
0042     void processTest(const QString& category, const QString& subcategory, const QString& dataset, DatasetHandler*);
0043 
0044 private:
0045     Ui::ImportDatasetWidget ui;
0046     DatasetsMap m_datasetsMap;
0047     bool m_allCollections{false};
0048     QString m_collection;
0049     QString m_category;
0050     QString m_subcategory;
0051     QString m_prevCollection;
0052     QString m_prevCategory;
0053     QString m_prevSubcategory;
0054     QString m_prevDataset;
0055     QCompleter* m_completer{nullptr};
0056     QString m_jsonDir;
0057     bool m_initializing{false};
0058     DatasetModel* m_model{nullptr};
0059     QNetworkAccessManager* m_networkManager;
0060     QJsonArray m_collections;
0061     QJsonObject m_datasetObject;
0062     QString m_collectionDescription;
0063     QString m_datasetDescription;
0064 
0065     void updateDatasetCompleter();
0066     void updateCategoryCompleter();
0067     void updateDatasets(QTreeWidgetItem*);
0068     void addDatasetItems(const QString& collection, const QString& category, const QString& subcategory, const QString& filter);
0069 
0070     void loadCategories();
0071     QJsonObject loadDatasetObject();
0072 
0073 private Q_SLOTS:
0074     void datasetChanged();
0075     void collectionChanged(int);
0076     void downloadFinished(QNetworkReply*);
0077     void updateCategories();
0078 
0079 Q_SIGNALS:
0080     void datasetSelected();
0081     void datasetDoubleClicked();
0082 };
0083 
0084 #endif // IMPORTDATASETWIDGET_H