diff --git a/src/kdefrontend/datasources/ImportDialog.cpp b/src/kdefrontend/datasources/ImportDialog.cpp index fc090e7cc..fb5b1219f 100644 --- a/src/kdefrontend/datasources/ImportDialog.cpp +++ b/src/kdefrontend/datasources/ImportDialog.cpp @@ -1,182 +1,178 @@ /*************************************************************************** File : ImportDialog.cc Project : LabPlot Description : import file data dialog -------------------------------------------------------------------- Copyright : (C) 2008-2017 Alexander Semke (alexander.semke@web.de) Copyright : (C) 2008-2015 by Stefan Gerlach (stefan.gerlach@uni.kn) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #include "ImportDialog.h" #include "backend/core/AspectTreeModel.h" #include "backend/core/Project.h" #include "backend/spreadsheet/Spreadsheet.h" #include "backend/matrix/Matrix.h" #include "backend/core/Workbook.h" #include "backend/lib/macros.h" #include "commonfrontend/widgets/TreeViewComboBox.h" #include "kdefrontend/MainWin.h" #include #include #include #include #include #include #include #include #include #include #include #include #include /*! \class ImportDialog \brief Base class for other import dialogs. Provides the "Import to" section of those dialogs. \ingroup kdefrontend */ ImportDialog::ImportDialog(MainWin* parent) : KDialog(parent), cbAddTo(0), cbPosition(0), m_mainWin(parent), m_newDataContainerMenu(0), m_aspectTreeModel(new AspectTreeModel(parent->project()) ) { QWidget* mainWidget = new QWidget(this); vLayout = new QVBoxLayout(mainWidget); vLayout->setSpacing(0); vLayout->setContentsMargins(0,0,0,0); setMainWidget(mainWidget); //menu for new data container m_newDataContainerMenu = new QMenu(this); m_newDataContainerMenu->addAction( QIcon::fromTheme("labplot-workbook-new"), i18n("new Workbook") ); m_newDataContainerMenu->addAction( QIcon::fromTheme("labplot-spreadsheet-new"), i18n("new Spreadsheet") ); m_newDataContainerMenu->addAction( QIcon::fromTheme("labplot-matrix-new"), i18n("new Matrix") ); connect(m_newDataContainerMenu, SIGNAL(triggered(QAction*)), this, SLOT(newDataContainer(QAction*))); //ok is only available if a valid container was selected enableButtonOk(false); } ImportDialog::~ImportDialog() { if (m_aspectTreeModel) delete m_aspectTreeModel; } /*! creates widgets for the frame "Import-To" and sets the current model in the "Add to"-combobox. */ void ImportDialog::setModel() { //Frame for the "Import To"-Stuff frameAddTo = new QGroupBox(this); frameAddTo->setTitle(i18n("Import To")); QGridLayout *grid = new QGridLayout(frameAddTo); grid->addWidget(new QLabel(i18n("Data container"), frameAddTo), 0, 0); cbAddTo = new TreeViewComboBox(frameAddTo); cbAddTo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); grid->addWidget(cbAddTo, 0, 1); QList list; list << "Folder" << "Spreadsheet" << "Matrix" << "Workbook"; cbAddTo->setTopLevelClasses(list); list.clear(); list << "Spreadsheet" << "Matrix" << "Workbook"; m_aspectTreeModel->setSelectableAspects(list); cbAddTo->setModel(m_aspectTreeModel); tbNewDataContainer = new QToolButton(frameAddTo); tbNewDataContainer->setIcon(QIcon::fromTheme("list-add")); tbNewDataContainer->setToolTip(i18n("Add new data container")); grid->addWidget( tbNewDataContainer, 0, 2); lPosition = new QLabel(i18n("Position"), frameAddTo); lPosition->setEnabled(false); grid->addWidget(lPosition, 1, 0); cbPosition = new QComboBox(frameAddTo); cbPosition->setEnabled(false); cbPosition->addItem(i18n("Append")); cbPosition->addItem(i18n("Prepend")); cbPosition->addItem(i18n("Replace")); KConfigGroup conf(KSharedConfig::openConfig(), "ImportDialog"); cbPosition->setCurrentIndex(conf.readEntry("Position", 0)); cbPosition->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); grid->addWidget(cbPosition, 1, 1); vLayout->addWidget(frameAddTo); connect(tbNewDataContainer, SIGNAL(clicked(bool)), this, SLOT(newDataContainerMenu())); - connect(cbAddTo, SIGNAL(currentModelIndexChanged(QModelIndex)), this, SLOT(modelIndexChanged())); + connect(cbAddTo, SIGNAL(currentModelIndexChanged(QModelIndex)), this, SLOT(checkOkButton())); } void ImportDialog::setCurrentIndex(const QModelIndex& index) { DEBUG("ImportFileDialog::setCurrentIndex()"); QDEBUG(" index =" << index); cbAddTo->setCurrentModelIndex(index); QDEBUG("cbAddTo->currentModelIndex() =" << cbAddTo->currentModelIndex()); checkOkButton(); } void ImportDialog::newDataContainer(QAction* action) { DEBUG("ImportDialog::newDataContainer()"); QString name = selectedObject(); QString type = action->iconText().split(' ')[1]; if (name.isEmpty()) name = action->iconText(); bool ok; // child widgets can't have own icons QInputDialog* dlg = new QInputDialog(this); name = dlg->getText(this, i18n("Add %1", action->iconText()), i18n("%1 name:", type), QLineEdit::Normal, name, &ok); if (ok) { AbstractAspect* aspect; int actionIndex = m_newDataContainerMenu->actions().indexOf(action); if (actionIndex == 0) aspect = new Workbook(0, name); else if (actionIndex == 1) aspect = new Spreadsheet(0, name); else aspect = new Matrix(0, name); m_mainWin->addAspectToProject(aspect); QDEBUG("cbAddTo->setCurrentModelIndex() to " << m_mainWin->model()->modelIndexOfAspect(aspect)); cbAddTo->setCurrentModelIndex(m_mainWin->model()->modelIndexOfAspect(aspect)); checkOkButton(); } delete dlg; } void ImportDialog::newDataContainerMenu() { m_newDataContainerMenu->exec( tbNewDataContainer->mapToGlobal(tbNewDataContainer->rect().bottomLeft())); } - -void ImportDialog::modelIndexChanged() { - checkOkButton(); -} diff --git a/src/kdefrontend/datasources/ImportDialog.h b/src/kdefrontend/datasources/ImportDialog.h index 1256f682e..3bceea2d6 100644 --- a/src/kdefrontend/datasources/ImportDialog.h +++ b/src/kdefrontend/datasources/ImportDialog.h @@ -1,80 +1,81 @@ /*************************************************************************** File : ImportDialog.h Project : LabPlot Description : import data dialog -------------------------------------------------------------------- Copyright : (C) 2016-2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef IMPORTDIALOG_H #define IMPORTDIALOG_H #include class AbstractAspect; class AspectTreeModel; class MainWin; class TreeViewComboBox; class QMenu; class QAbstractItemModel; class QLabel; class QModelIndex; class QVBoxLayout; class QComboBox; class QGroupBox; class QToolButton; class QStatusBar; class ImportDialog : public KDialog { Q_OBJECT public: explicit ImportDialog(MainWin*); ~ImportDialog(); virtual void importTo(QStatusBar*) const = 0; void setCurrentIndex(const QModelIndex&); virtual QString selectedObject() const = 0; - virtual void checkOkButton() = 0; protected: void setModel(); QVBoxLayout* vLayout; TreeViewComboBox* cbAddTo; QLabel* lPosition; QComboBox* cbPosition; MainWin* m_mainWin; QGroupBox* frameAddTo; QToolButton* tbNewDataContainer; QMenu* m_newDataContainerMenu; AspectTreeModel* m_aspectTreeModel; +protected slots: + virtual void checkOkButton() = 0; + private slots: void newDataContainerMenu(); void newDataContainer(QAction*); - void modelIndexChanged(); }; #endif //IMPORTDIALOG_H diff --git a/src/kdefrontend/datasources/ImportFileDialog.cpp b/src/kdefrontend/datasources/ImportFileDialog.cpp index f6356eae9..79e86ca60 100644 --- a/src/kdefrontend/datasources/ImportFileDialog.cpp +++ b/src/kdefrontend/datasources/ImportFileDialog.cpp @@ -1,356 +1,348 @@ /*************************************************************************** File : ImportDialog.cc Project : LabPlot Description : import file data dialog -------------------------------------------------------------------- Copyright : (C) 2008-2017 Alexander Semke (alexander.semke@web.de) Copyright : (C) 2008-2015 by Stefan Gerlach (stefan.gerlach@uni.kn) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #include "ImportFileDialog.h" #include "ImportFileWidget.h" #include "backend/core/AspectTreeModel.h" #include "backend/datasources/LiveDataSource.h" #include "backend/datasources/filters/AbstractFileFilter.h" #include "backend/datasources/filters/HDFFilter.h" #include "backend/datasources/filters/NetCDFFilter.h" #include "backend/spreadsheet/Spreadsheet.h" #include "backend/matrix/Matrix.h" #include "backend/core/Workbook.h" #include "commonfrontend/widgets/TreeViewComboBox.h" #include "kdefrontend/MainWin.h" #include #include #include #include #include #include #include #include #include #include /*! \class ImportFileDialog \brief Dialog for importing data from a file. Embeds \c ImportFileWidget and provides the standard buttons. \ingroup kdefrontend */ ImportFileDialog::ImportFileDialog(MainWin* parent, bool liveDataSource, const QString& fileName) : ImportDialog(parent), m_importFileWidget(new ImportFileWidget(this, fileName)), m_showOptions(false) { vLayout->addWidget(m_importFileWidget); setButtons(KDialog::Ok | KDialog::User1 | KDialog::Cancel); //hide the data-source related widgets if (!liveDataSource) { setModel(); //TODO: disable for file data sources m_importFileWidget->hideDataSource(); } else m_importFileWidget->initializeAndFillPortsAndBaudRates(); connect(this, SIGNAL(user1Clicked()), this, SLOT(toggleOptions())); - connect(m_importFileWidget, SIGNAL(fileNameChanged()), this, SLOT(fileNameChanged())); connect(m_importFileWidget, SIGNAL(checkedFitsTableToMatrix(bool)), this, SLOT(checkOnFitsTableToMatrix(bool))); - connect(m_importFileWidget, SIGNAL(sourceTypeChanged()), this, SLOT(checkOk())); - connect(m_importFileWidget, SIGNAL(hostChanged()), this, SLOT(checkOk())); - connect(m_importFileWidget, SIGNAL(portChanged()), this, SLOT(checkOk())); + connect(m_importFileWidget, SIGNAL(fileNameChanged()), this, SLOT(checkOkButton())); + connect(m_importFileWidget, SIGNAL(sourceTypeChanged()), this, SLOT(checkOkButton())); + connect(m_importFileWidget, SIGNAL(hostChanged()), this, SLOT(checkOkButton())); + connect(m_importFileWidget, SIGNAL(portChanged()), this, SLOT(checkOkButton())); if (!liveDataSource) { setCaption(i18n("Import Data to Spreadsheet or Matrix")); m_importFileWidget->hideDataSource(); } else setCaption(i18n("Add new live data source")); setWindowIcon(QIcon::fromTheme("document-import-database")); QTimer::singleShot(0, this, &ImportFileDialog::loadSettings); } void ImportFileDialog::loadSettings() { //restore saved settings QApplication::processEvents(QEventLoop::AllEvents, 0); KConfigGroup conf(KSharedConfig::openConfig(), "ImportFileDialog"); m_showOptions = conf.readEntry("ShowOptions", false); m_showOptions ? setButtonText(KDialog::User1, i18n("Hide Options")) : setButtonText(KDialog::User1, i18n("Show Options")); m_importFileWidget->showOptions(m_showOptions); KWindowConfig::restoreWindowSize(windowHandle(), conf); } ImportFileDialog::~ImportFileDialog() { //save current settings KConfigGroup conf(KSharedConfig::openConfig(), "ImportFileDialog"); conf.writeEntry("ShowOptions", m_showOptions); if (cbPosition) conf.writeEntry("Position", cbPosition->currentIndex()); KWindowConfig::saveWindowSize(windowHandle(), conf); } /*! triggers data import to the live data source \c source */ void ImportFileDialog::importToLiveDataSource(LiveDataSource* source, QStatusBar* statusBar) const { m_importFileWidget->saveSettings(source); //show a progress bar in the status bar QProgressBar* progressBar = new QProgressBar(); progressBar->setRange(0, 100); connect(source->filter(), SIGNAL(completed(int)), progressBar, SLOT(setValue(int))); statusBar->clearMessage(); statusBar->addWidget(progressBar, 1); WAIT_CURSOR; QTime timer; timer.start(); source->read(); statusBar->showMessage( i18n("Live data source created in %1 seconds.", (float)timer.elapsed()/1000) ); RESET_CURSOR; statusBar->removeWidget(progressBar); source->ready(); } /*! triggers data import to the currently selected data container */ void ImportFileDialog::importTo(QStatusBar* statusBar) const { DEBUG("ImportFileDialog::importTo()"); QDEBUG("cbAddTo->currentModelIndex() =" << cbAddTo->currentModelIndex()); AbstractAspect* aspect = static_cast(cbAddTo->currentModelIndex().internalPointer()); if (!aspect) { DEBUG("ERROR in importTo(): No aspect available"); DEBUG("cbAddTo->currentModelIndex().isValid() = " << cbAddTo->currentModelIndex().isValid()); DEBUG("cbAddTo->currentModelIndex() row/column = " << cbAddTo->currentModelIndex().row() << ' ' << cbAddTo->currentModelIndex().column()); return; } QString fileName = m_importFileWidget->fileName(); AbstractFileFilter* filter = m_importFileWidget->currentFileFilter(); AbstractFileFilter::ImportMode mode = AbstractFileFilter::ImportMode(cbPosition->currentIndex()); //show a progress bar in the status bar QProgressBar* progressBar = new QProgressBar(); progressBar->setRange(0, 100); connect(filter, SIGNAL(completed(int)), progressBar, SLOT(setValue(int))); statusBar->clearMessage(); statusBar->addWidget(progressBar, 1); WAIT_CURSOR; QApplication::processEvents(QEventLoop::AllEvents, 100); QTime timer; timer.start(); if (aspect->inherits("Matrix")) { Matrix* matrix = qobject_cast(aspect); filter->readDataFromFile(fileName, matrix, mode); } else if (aspect->inherits("Spreadsheet")) { Spreadsheet* spreadsheet = qobject_cast(aspect); filter->readDataFromFile(fileName, spreadsheet, mode); } else if (aspect->inherits("Workbook")) { Workbook* workbook = qobject_cast(aspect); QList sheets = workbook->children(); QStringList names; LiveDataSource::FileType fileType = m_importFileWidget->currentFileType(); if (fileType == LiveDataSource::HDF) names = m_importFileWidget->selectedHDFNames(); else if (fileType == LiveDataSource::NETCDF) names = m_importFileWidget->selectedNetCDFNames(); //multiple extensions selected // multiple data sets/variables for HDF/NetCDF if (fileType == LiveDataSource::HDF || fileType == LiveDataSource::NETCDF) { int nrNames = names.size(), offset = sheets.size(); int start=0; if (mode == AbstractFileFilter::Replace) start=offset; // add additional sheets for (int i = start; i < nrNames; i++) { Spreadsheet *spreadsheet = new Spreadsheet(0, i18n("Spreadsheet")); if (mode == AbstractFileFilter::Prepend) workbook->insertChildBefore(spreadsheet,sheets[0]); else workbook->addChild(spreadsheet); } if (mode != AbstractFileFilter::Append) offset = 0; // import to sheets sheets = workbook->children(); for (int i = 0; i < nrNames; i++) { if (fileType == LiveDataSource::HDF) ((HDFFilter*) filter)->setCurrentDataSetName(names[i]); else ((NetCDFFilter*) filter)->setCurrentVarName(names[i]); if (sheets[i+offset]->inherits("Matrix")) filter->readDataFromFile(fileName, qobject_cast(sheets[i+offset])); else if (sheets[i+offset]->inherits("Spreadsheet")) filter->readDataFromFile(fileName, qobject_cast(sheets[i+offset])); } } else { // single import file types // use active spreadsheet/matrix if present, else new spreadsheet Spreadsheet* spreadsheet = workbook->currentSpreadsheet(); Matrix* matrix = workbook->currentMatrix(); if (spreadsheet) filter->readDataFromFile(fileName, spreadsheet, mode); else if (matrix) filter->readDataFromFile(fileName, matrix, mode); else { spreadsheet = new Spreadsheet(0, i18n("Spreadsheet")); workbook->addChild(spreadsheet); filter->readDataFromFile(fileName, spreadsheet, mode); } } } statusBar->showMessage( i18n("File %1 imported in %2 seconds.", fileName, (float)timer.elapsed()/1000) ); RESET_CURSOR; statusBar->removeWidget(progressBar); delete filter; } -void ImportFileDialog::fileNameChanged() { - checkOkButton(); -} - -void ImportFileDialog::checkOk() { - checkOkButton();; -} - void ImportFileDialog::toggleOptions() { m_importFileWidget->showOptions(!m_showOptions); m_showOptions = !m_showOptions; m_showOptions ? setButtonText(KDialog::User1,i18n("Hide Options")) : setButtonText(KDialog::User1,i18n("Show Options")); //resize the dialog mainWidget()->resize(layout()->minimumSize()); layout()->activate(); resize( QSize(this->width(), 0).expandedTo(minimumSize()) ); } void ImportFileDialog::checkOnFitsTableToMatrix(const bool enable) { if (cbAddTo) { QDEBUG("cbAddTo->currentModelIndex() = " << cbAddTo->currentModelIndex()); AbstractAspect* aspect = static_cast(cbAddTo->currentModelIndex().internalPointer()); if (!aspect) { DEBUG("ERROR: no aspect available."); return; } if(aspect->inherits("Matrix")) enableButtonOk(enable); } } void ImportFileDialog::checkOkButton() { DEBUG("ImportFileDialog::checkOkButton()"); if (cbAddTo) { //only check for the target container when no file data source is being added QDEBUG(" cbAddTo->currentModelIndex() = " << cbAddTo->currentModelIndex()); AbstractAspect* aspect = static_cast(cbAddTo->currentModelIndex().internalPointer()); if (!aspect) { enableButtonOk(false); lPosition->setEnabled(false); cbPosition->setEnabled(false); DEBUG("WARNING: no aspect available."); return; } else { DEBUG("Aspect available."); lPosition->setEnabled(true); cbPosition->setEnabled(true); //when doing ASCII import to a matrix, hide the options for using the file header (first line) //to name the columns since the column names are fixed in a matrix const Matrix* matrix = dynamic_cast(aspect); m_importFileWidget->showAsciiHeaderOptions(matrix == NULL); } } QString fileName = m_importFileWidget->fileName(); if (m_importFileWidget->currentFileType() != LiveDataSource::FITS) { #ifndef HAVE_WINDOWS if (!fileName.isEmpty() && fileName.left(1) != QDir::separator()) fileName = QDir::homePath() + QDir::separator() + fileName; #endif } else { // LiveDataSource::FITS int extensionBraceletPos = -1; if (!fileName.isEmpty()) { if(fileName.right(1) == QLatin1String("]")) { for (int i = fileName.size() - 1; i >= 5; --i) { if (fileName.at(i) == QLatin1Char('[')) { extensionBraceletPos = i; break; } } } } #ifndef HAVE_WINDOWS if (fileName.left(1) != QDir::separator()) fileName = QDir::homePath() + QDir::separator() + fileName.mid(0, extensionBraceletPos); else #endif fileName = fileName.mid(0, extensionBraceletPos); } DEBUG(" fileName = " << fileName.toUtf8().constData()); bool enable = !m_importFileWidget->host().isEmpty() && !m_importFileWidget->port().isEmpty(); switch (m_importFileWidget->currentSourceType()) { case LiveDataSource::SourceType::FileOrPipe: enableButtonOk( QFile::exists(fileName) ); break; case LiveDataSource::SourceType::LocalSocket: enableButtonOk( QFile::exists(fileName) ); break; case LiveDataSource::SourceType::NetworkTcpSocket: enableButtonOk(enable); break; case LiveDataSource::SourceType::NetworkUdpSocket: enableButtonOk(enable); break; case LiveDataSource::SourceType::SerialPort: enableButtonOk(m_importFileWidget->serialPort() != -1); break; default: break; } } QString ImportFileDialog::selectedObject() const { QString path = m_importFileWidget->fileName(); QString name = path.right( path.length()-path.lastIndexOf(QDir::separator())-1 ); return name; } diff --git a/src/kdefrontend/datasources/ImportFileDialog.h b/src/kdefrontend/datasources/ImportFileDialog.h index 27ecd52a9..14b63988a 100644 --- a/src/kdefrontend/datasources/ImportFileDialog.h +++ b/src/kdefrontend/datasources/ImportFileDialog.h @@ -1,71 +1,69 @@ /*************************************************************************** File : ImportFileDialog.h Project : LabPlot Description : import data dialog -------------------------------------------------------------------- Copyright : (C) 2008-2017 Alexander Semke (alexander.semke@web.de) Copyright : (C) 2008-2015 by Stefan Gerlach (stefan.gerlach@uni.kn) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef IMPORTFILEDIALOG_H #define IMPORTFILEDIALOG_H #include "ImportDialog.h" class AbstractAspect; class MainWin; class ImportFileWidget; class LiveDataSource; class TreeViewComboBox; class QStatusBar; class QMenu; class ImportFileDialog : public ImportDialog { Q_OBJECT public: explicit ImportFileDialog(MainWin*, bool liveDataSource = false, const QString& fileName = QString()); ~ImportFileDialog(); virtual QString selectedObject() const; - virtual void checkOkButton(); void importToLiveDataSource(LiveDataSource*, QStatusBar*) const; virtual void importTo(QStatusBar*) const; private: ImportFileWidget* m_importFileWidget; bool m_showOptions; QMenu* m_newDataContainerMenu; - +protected slots: + virtual void checkOkButton(); private slots: void toggleOptions(); - void fileNameChanged(); - void checkOk(); void checkOnFitsTableToMatrix(const bool enable); void loadSettings(); }; #endif //IMPORTFILEDIALOG_H diff --git a/src/kdefrontend/datasources/ImportSQLDatabaseDialog.cpp b/src/kdefrontend/datasources/ImportSQLDatabaseDialog.cpp index 659d00214..7dbde04a0 100644 --- a/src/kdefrontend/datasources/ImportSQLDatabaseDialog.cpp +++ b/src/kdefrontend/datasources/ImportSQLDatabaseDialog.cpp @@ -1,167 +1,163 @@ /*************************************************************************** File : ImportSQLDatabaseDialog.cpp Project : LabPlot Description : import SQL dataase dialog -------------------------------------------------------------------- Copyright : (C) 2016 by Ankit Wagadre (wagadre.ankit@gmail.com) Copyright : (C) 2016-2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #include "ImportSQLDatabaseDialog.h" #include "ImportSQLDatabaseWidget.h" #include "backend/core/AspectTreeModel.h" #include "backend/lib/macros.h" #include "kdefrontend/MainWin.h" #include "backend/spreadsheet/Spreadsheet.h" #include "backend/matrix/Matrix.h" #include "backend/core/Workbook.h" #include "commonfrontend/widgets/TreeViewComboBox.h" #include #include #include #include /*! \class ImportSQLDatabaseDialog \brief Dialog for importing data from a SQL database. Embeds \c ImportSQLDatabaseWidget and provides the standard buttons. \ingroup kdefrontend */ ImportSQLDatabaseDialog::ImportSQLDatabaseDialog(MainWin* parent) : ImportDialog(parent), importSQLDatabaseWidget(new ImportSQLDatabaseWidget(this)) { vLayout->addWidget(importSQLDatabaseWidget); setButtons( KDialog::Ok | KDialog::Cancel ); setCaption(i18n("Import Data to Spreadsheet or Matrix")); setWindowIcon(QIcon::fromTheme("document-import-database")); setModel(); - connect( importSQLDatabaseWidget, SIGNAL(stateChanged()), this, SLOT(importWidgetStateChanged()) ); + connect(importSQLDatabaseWidget, SIGNAL(stateChanged()), this, SLOT(checkOkButton())); QTimer::singleShot(0, this, &ImportSQLDatabaseDialog::loadSettings); } void ImportSQLDatabaseDialog::loadSettings() { //restore saved settings QApplication::processEvents(QEventLoop::AllEvents, 0); KConfigGroup conf(KSharedConfig::openConfig(), "ImportSQLDatabaseDialog"); KWindowConfig::restoreWindowSize(windowHandle(), conf); } ImportSQLDatabaseDialog::~ImportSQLDatabaseDialog() { //save current settings KConfigGroup conf(KSharedConfig::openConfig(), "ImportSQLDatabaseDialog"); KWindowConfig::saveWindowSize(windowHandle(), conf); } void ImportSQLDatabaseDialog::importTo(QStatusBar* statusBar) const { DEBUG("ImportSQLDatabaseDialog::import()"); AbstractAspect* aspect = static_cast(cbAddTo->currentModelIndex().internalPointer()); if (!aspect) { DEBUG("ERROR: No aspect available!"); return; } AbstractFileFilter::ImportMode mode = AbstractFileFilter::ImportMode(cbPosition->currentIndex()); //show a progress bar in the status bar QProgressBar* progressBar = new QProgressBar(); progressBar->setMinimum(0); progressBar->setMaximum(100); connect(importSQLDatabaseWidget, SIGNAL(completed(int)), progressBar, SLOT(setValue(int))); statusBar->clearMessage(); statusBar->addWidget(progressBar, 1); WAIT_CURSOR; QApplication::processEvents(QEventLoop::AllEvents, 100); QTime timer; timer.start(); if (aspect->inherits("Matrix")) { Matrix* matrix = qobject_cast(aspect); importSQLDatabaseWidget->read(matrix, mode); } else if (aspect->inherits("Spreadsheet")) { Spreadsheet* spreadsheet = qobject_cast(aspect); importSQLDatabaseWidget->read(spreadsheet, mode); } else if (aspect->inherits("Workbook")) { // use active spreadsheet or matrix (only if numeric data is going to be improted) if present, // create a new spreadsheet in the selected workbook otherwise Workbook* workbook = qobject_cast(aspect); Spreadsheet* spreadsheet = workbook->currentSpreadsheet(); Matrix* matrix = workbook->currentMatrix(); if (spreadsheet) importSQLDatabaseWidget->read(spreadsheet, mode); else if (matrix && importSQLDatabaseWidget->isNumericData()) importSQLDatabaseWidget->read(matrix, mode); else { spreadsheet = new Spreadsheet(0, i18n("Spreadsheet")); workbook->addChild(spreadsheet); importSQLDatabaseWidget->read(spreadsheet, mode); } } statusBar->showMessage( i18n("Data imported in %1 seconds.", (float)timer.elapsed()/1000) ); RESET_CURSOR; statusBar->removeWidget(progressBar); } QString ImportSQLDatabaseDialog::selectedObject() const { return importSQLDatabaseWidget->selectedTable(); } void ImportSQLDatabaseDialog::checkOkButton() { DEBUG("ImportSQLDatabaseDialog::checkOkButton()"); AbstractAspect* aspect = static_cast(cbAddTo->currentModelIndex().internalPointer()); if (!aspect) { enableButtonOk(false); cbPosition->setEnabled(false); return; } //check whether a valid connection and an object to import were selected if (!importSQLDatabaseWidget->isValid()) { enableButtonOk(false); cbPosition->setEnabled(false); return; } //for matrix containers allow to import only numerical data if (dynamic_cast(aspect) && !importSQLDatabaseWidget->isNumericData()) { enableButtonOk(false); cbPosition->setEnabled(false); return; } enableButtonOk(true); cbPosition->setEnabled(true); } - -void ImportSQLDatabaseDialog::importWidgetStateChanged() { - checkOkButton(); -} diff --git a/src/kdefrontend/datasources/ImportSQLDatabaseDialog.h b/src/kdefrontend/datasources/ImportSQLDatabaseDialog.h index e01ee2c88..05b505dd0 100644 --- a/src/kdefrontend/datasources/ImportSQLDatabaseDialog.h +++ b/src/kdefrontend/datasources/ImportSQLDatabaseDialog.h @@ -1,58 +1,57 @@ /*************************************************************************** File : ImportSQLDatabaseDialog.h Project : LabPlot Description : import SQL database dialog -------------------------------------------------------------------- Copyright : (C) 2016 by Ankit Wagadre (wagadre.ankit@gmail.com) Copyright : (C) 2016-2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef IMPORTSQLDATABASEDIALOG_H #define IMPORTSQLDATABASEDIALOG_H #include "kdefrontend/datasources/ImportDialog.h" class MainWin; class QStatusBar; class ImportSQLDatabaseWidget; class ImportSQLDatabaseDialog : public ImportDialog { Q_OBJECT public: explicit ImportSQLDatabaseDialog(MainWin*); ~ImportSQLDatabaseDialog(); void importTo(QStatusBar*) const; virtual QString selectedObject() const; - virtual void checkOkButton(); private: ImportSQLDatabaseWidget* importSQLDatabaseWidget; - +protected slots: + virtual void checkOkButton(); private slots: - void importWidgetStateChanged(); void loadSettings(); }; #endif //IMPORTSQLDATABASEDIALOG_H diff --git a/src/kdefrontend/spreadsheet/PlotDataDialog.h b/src/kdefrontend/spreadsheet/PlotDataDialog.h index 5c2cbec2b..bb55b7430 100644 --- a/src/kdefrontend/spreadsheet/PlotDataDialog.h +++ b/src/kdefrontend/spreadsheet/PlotDataDialog.h @@ -1,74 +1,74 @@ /*************************************************************************** File : PlotDataDialog.h Project : LabPlot Description : Dialog for generating plots for the spreadsheet data -------------------------------------------------------------------- Copyright : (C) 2017 by Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef PLOTDATADIALOG_H #define PLOTDATADIALOG_H #include "ui_plotdatawidget.h" #include class QComboBox; class AspectTreeModel; class CartesianPlot; class Column; class Spreadsheet; class TreeViewComboBox; class Worksheet; class PlotDataDialog : public QDialog { Q_OBJECT public: explicit PlotDataDialog(Spreadsheet*, QWidget* parent = 0, Qt::WFlags fl = 0); ~PlotDataDialog(); private: Ui::PlotDataWidget ui; QPushButton* m_okButton; Spreadsheet* m_spreadsheet; TreeViewComboBox* cbExistingPlots; TreeViewComboBox* cbExistingWorksheets; QList m_columns; QList m_columnComboBoxes; AspectTreeModel* m_plotsModel; AspectTreeModel* m_worksheetsModel; void processColumns(); void addCurvesToPlot(CartesianPlot*) const; void addCurvesToPlots(Worksheet*) const; Column* columnFromName(const QString&) const; - +protected slots: + virtual void checkOkButton(); private slots: void plot(); void curvePlacementChanged(); void plotPlacementChanged(); - void checkOkButton(); void loadSettings(); }; #endif