File indexing completed on 2024-05-12 15:27:47
0001 /*************************************************************************** 0002 File : ImportDatasetDialog.cpp 0003 Project : LabPlot 0004 Description : import dataset data dialog 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2019 Ferencz Koovacs (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 "ImportDatasetDialog.h" 0030 #include "ImportDatasetWidget.h" 0031 #include "backend/datasources/DatasetHandler.h" 0032 0033 #include "QDialogButtonBox" 0034 #include <QElapsedTimer> 0035 #include "QProgressBar" 0036 #include "QPushButton" 0037 #include "QStatusBar" 0038 #include "QWindow" 0039 0040 #include "KConfigGroup" 0041 #include "KSharedConfig" 0042 #include "KWindowConfig" 0043 0044 /*! 0045 \class ImportDatasetDialog 0046 \brief Dialog for importing data from a dataset. Embeds \c ImportDatasetWidget and provides the standard buttons. 0047 0048 \ingroup kdefrontend 0049 */ 0050 ImportDatasetDialog::ImportDatasetDialog(MainWin* parent) : ImportDialog(parent), 0051 m_importDatasetWidget(new ImportDatasetWidget(this)){ 0052 0053 vLayout->addWidget(m_importDatasetWidget); 0054 connect(m_importDatasetWidget, &ImportDatasetWidget::datasetSelected, this, &ImportDatasetDialog::checkOkButton); 0055 connect(m_importDatasetWidget, &ImportDatasetWidget::datasetDoubleClicked, [this]() { 0056 checkOkButton(); 0057 if(okButton->isEnabled()) 0058 accept(); 0059 }); 0060 0061 //dialog buttons 0062 auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |QDialogButtonBox::Cancel); 0063 okButton = buttonBox->button(QDialogButtonBox::Ok); 0064 okButton->setEnabled(false); //ok is only available if a valid container was selected 0065 vLayout->addWidget(buttonBox); 0066 0067 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0068 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0069 0070 setWindowTitle(i18nc("@title:window", "Import from Dataset Collection")); 0071 create(); 0072 0073 QApplication::processEvents(QEventLoop::AllEvents, 0); 0074 0075 KConfigGroup conf(KSharedConfig::openConfig(), "ImportDatasetDialog"); 0076 if (conf.exists()) { 0077 KWindowConfig::restoreWindowSize(windowHandle(), conf); 0078 resize(windowHandle()->size()); 0079 } else 0080 resize(QSize(0, 0).expandedTo(minimumSize())); 0081 0082 ImportDatasetDialog::checkOkButton(); 0083 } 0084 0085 ImportDatasetDialog::~ImportDatasetDialog() { 0086 KConfigGroup conf(KSharedConfig::openConfig(), "ImportDatasetDialog"); 0087 KWindowConfig::saveWindowSize(windowHandle(), conf); 0088 } 0089 0090 QString ImportDatasetDialog::selectedObject() const { 0091 return QString(); 0092 } 0093 0094 /*! 0095 triggers the import of a dataset's data 0096 */ 0097 void ImportDatasetDialog::importToDataset(DatasetHandler* datasetHandler, QStatusBar* statusBar) const { 0098 //show a progress bar in the status bar 0099 auto* progressBar = new QProgressBar(); 0100 progressBar->setRange(0, 100); 0101 connect(datasetHandler, &DatasetHandler::downloadProgress, progressBar, &QProgressBar::setValue); 0102 0103 statusBar->clearMessage(); 0104 statusBar->addWidget(progressBar, 1); 0105 0106 WAIT_CURSOR; 0107 QApplication::processEvents(QEventLoop::AllEvents, 100); 0108 0109 QElapsedTimer timer; 0110 timer.start(); 0111 0112 m_importDatasetWidget->import(datasetHandler); 0113 0114 statusBar->showMessage(i18n("Dataset imported in %1 seconds.", static_cast<float>(timer.elapsed())/1000)); 0115 RESET_CURSOR; 0116 statusBar->removeWidget(progressBar); 0117 } 0118 0119 /** 0120 * @brief Checks whether the OK button of the dialog can be pressed or not 0121 */ 0122 void ImportDatasetDialog::checkOkButton() { 0123 bool enable = (!m_importDatasetWidget->getSelectedDataset().isEmpty()); 0124 okButton->setEnabled(enable); 0125 } 0126 0127 void ImportDatasetDialog::importTo(QStatusBar* statusBar) const { 0128 Q_UNUSED(statusBar); 0129 }