diff --git a/src/kdefrontend/datasources/FITSOptionsWidget.cpp b/src/kdefrontend/datasources/FITSOptionsWidget.cpp index d402658bb..349f85ac3 100644 --- a/src/kdefrontend/datasources/FITSOptionsWidget.cpp +++ b/src/kdefrontend/datasources/FITSOptionsWidget.cpp @@ -1,176 +1,177 @@ /*************************************************************************** File : FITSOptionsWidget.cpp Project : LabPlot Description : Widget providing options for the import of FITS data -------------------------------------------------------------------- Copyright : (C) 2016 Fabian Kristof (fkristofszabolcs@gmail.com) Copyright : (C) 2017 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 "FITSOptionsWidget.h" #include "ImportFileWidget.h" #include "backend/datasources/filters/FITSFilter.h" #include "backend/lib/macros.h" FITSOptionsWidget::FITSOptionsWidget(QWidget* parent, ImportFileWidget* fileWidget) : QWidget(parent), m_fileWidget(fileWidget) { ui.setupUi(parent); ui.twExtensions->headerItem()->setText(0, i18n("Content")); ui.twExtensions->setSelectionMode(QAbstractItemView::SingleSelection); ui.twExtensions->setAlternatingRowColors(true); + ui.twExtensions->header()->setSectionResizeMode(QHeaderView::ResizeToContents); ui.twPreview->setEditTriggers(QAbstractItemView::NoEditTriggers); connect( ui.twExtensions, SIGNAL(itemSelectionChanged()), SLOT(fitsTreeWidgetSelectionChanged())); connect( ui.bRefreshPreview, SIGNAL(clicked()), fileWidget, SLOT(refreshPreview()) ); } void FITSOptionsWidget::clear() { ui.twExtensions->clear(); ui.twPreview->clear(); } QString FITSOptionsWidget::currentExtensionName() { QString name; if (ui.twExtensions->currentItem() != 0 && ui.twExtensions->currentItem()->text(0) != i18n("Primary header")) name = ui.twExtensions->currentItem()->text(ui.twExtensions->currentColumn()); return name; } void FITSOptionsWidget::updateContent(FITSFilter *filter, const QString& fileName) { ui.twExtensions->clear(); filter->parseExtensions(fileName, ui.twExtensions, true); } /*! updates the selected var name of a NetCDF file when the tree widget item is selected */ //TODO void FITSOptionsWidget::fitsTreeWidgetSelectionChanged() { DEBUG("fitsTreeWidgetSelectionChanges()"); QDEBUG("SELECTED ITEMS =" << ui.twExtensions->selectedItems()); if (ui.twExtensions->selectedItems().isEmpty()) return; QTreeWidgetItem* item = ui.twExtensions->selectedItems().first(); int column = ui.twExtensions->currentColumn(); WAIT_CURSOR; const QString& itemText = item->text(column); QString selectedExtension; int extType = 0; if (itemText.contains(QLatin1String("IMAGE #")) || itemText.contains(QLatin1String("ASCII_TBL #")) || itemText.contains(QLatin1String("BINARY_TBL #"))) extType = 1; else if (!itemText.compare(i18n("Primary header"))) extType = 2; if (extType == 0) { if (item->parent() != 0) { if (item->parent()->parent() != 0) selectedExtension = item->parent()->parent()->text(0) + QLatin1String("[") + item->text(column) + QLatin1String("]"); } } else if (extType == 1) { if (item->parent() != 0) { if (item->parent()->parent() != 0) { bool ok; int hduNum = itemText.right(1).toInt(&ok); selectedExtension = item->parent()->parent()->text(0) + QLatin1String("[") + QString::number(hduNum-1) + QLatin1String("]"); } } } else { if (item->parent()->parent() != 0) selectedExtension = item->parent()->parent()->text(column); } if (!selectedExtension.isEmpty()) { FITSFilter* filter = dynamic_cast(m_fileWidget->currentFileFilter()); bool readFitsTableToMatrix; const QVector importedStrings = filter->readChdu(selectedExtension, &readFitsTableToMatrix, ui.sbPreviewLines->value()); emit m_fileWidget->checkedFitsTableToMatrix(readFitsTableToMatrix); const int rows = importedStrings.size(); ui.twPreview->clear(); ui.twPreview->setRowCount(rows); int colCount = 0; const int maxColumns = 300; for (int i = 0; i < rows; i++) { QStringList lineString = importedStrings[i]; if (i == 0) { colCount = lineString.size() > maxColumns ? maxColumns : lineString.size(); ui.twPreview->setColumnCount(colCount); } colCount = lineString.size() > maxColumns ? maxColumns : lineString.size(); for (int j = 0; j < colCount; j++) { QTableWidgetItem* item = new QTableWidgetItem(lineString[j]); ui.twPreview->setItem(i, j, item); } } ui.twPreview->resizeColumnsToContents(); } RESET_CURSOR; } /*! return list of selected FITS extension names */ const QStringList FITSOptionsWidget::selectedFITSExtensions() const { QStringList names; for (const auto* item: ui.twExtensions->selectedItems()) names << item->text(0); return names; } const QString FITSOptionsWidget::extensionName(bool* ok) { if (ui.twExtensions->currentItem() != 0) { const QTreeWidgetItem* item = ui.twExtensions->currentItem(); const int currentColumn = ui.twExtensions->currentColumn(); QString itemText = item->text(currentColumn); int extType = 0; if (itemText.contains(QLatin1String("IMAGE #")) || itemText.contains(QLatin1String("ASCII_TBL #")) || itemText.contains(QLatin1String("BINARY_TBL #"))) extType = 1; else if (!itemText.compare(i18n("Primary header"))) extType = 2; if (extType == 0) { if (item->parent() != 0 && item->parent()->parent() != 0) return item->parent()->parent()->text(0) + QLatin1String("[")+ item->text(currentColumn) + QLatin1String("]"); } else if (extType == 1) { if (item->parent() != 0 && item->parent()->parent() != 0) { int hduNum = itemText.right(1).toInt(ok); return item->parent()->parent()->text(0) + QLatin1String("[") + QString::number(hduNum-1) + QLatin1String("]"); } } else { if (item->parent()->parent() != 0) return item->parent()->parent()->text(currentColumn); } } return QString(); } diff --git a/src/kdefrontend/datasources/HDFOptionsWidget.cpp b/src/kdefrontend/datasources/HDFOptionsWidget.cpp index ce5d8e906..77818ae85 100644 --- a/src/kdefrontend/datasources/HDFOptionsWidget.cpp +++ b/src/kdefrontend/datasources/HDFOptionsWidget.cpp @@ -1,102 +1,103 @@ /*************************************************************************** File : HDFOptionsWidget.cpp Project : LabPlot Description : widget providing options for the import of HDF data -------------------------------------------------------------------- Copyright : (C) 2015-2017 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 "HDFOptionsWidget.h" #include "ImportFileWidget.h" #include "backend/datasources/filters/HDFFilter.h" #include "backend/lib/macros.h" /*! \class HDFOptionsWidget \brief Widget providing options for the import of HDF data \ingroup kdefrontend */ HDFOptionsWidget::HDFOptionsWidget(QWidget* parent, ImportFileWidget* fileWidget) : QWidget(parent), m_fileWidget(fileWidget) { ui.setupUi(parent); QStringList hdfheaders; hdfheaders << i18n("Name") << i18n("Link") << i18n("Type") << i18n("Properties") << i18n("Attributes"); ui.twContent->setHeaderLabels(hdfheaders); ui.twContent->setAlternatingRowColors(true); // link and type column are hidden ui.twContent->hideColumn(1); ui.twContent->hideColumn(2); ui.twContent->setSelectionMode(QAbstractItemView::ExtendedSelection); + ui.twContent->header()->setSectionResizeMode(QHeaderView::ResizeToContents); ui.twPreview->setEditTriggers(QAbstractItemView::NoEditTriggers); ui.bRefreshPreview->setIcon( QIcon::fromTheme("view-refresh") ); connect( ui.twContent, SIGNAL(itemSelectionChanged()), SLOT(hdfTreeWidgetSelectionChanged()) ); connect( ui.bRefreshPreview, SIGNAL(clicked()), fileWidget, SLOT(refreshPreview()) ); } void HDFOptionsWidget::clear() { ui.twContent->clear(); ui.twPreview->clear(); } void HDFOptionsWidget::updateContent(HDFFilter *filter, QString fileName) { ui.twContent->clear(); QTreeWidgetItem *rootItem = ui.twContent->invisibleRootItem(); filter->parse(fileName, rootItem); ui.twContent->insertTopLevelItem(0, rootItem); ui.twContent->expandAll(); ui.twContent->resizeColumnToContents(0); ui.twContent->resizeColumnToContents(3); } /*! updates the selected data set of a HDF file when a new tree widget item is selected */ void HDFOptionsWidget::hdfTreeWidgetSelectionChanged() { DEBUG("hdfTreeWidgetSelectionChanged()"); auto items = ui.twContent->selectedItems(); QDEBUG("SELECTED ITEMS =" << items); if (items.isEmpty()) return; QTreeWidgetItem* item = items.first(); if (item->data(2, Qt::DisplayRole).toString() == i18n("data set")) m_fileWidget->refreshPreview(); else DEBUG("non data set selected in HDF tree widget"); } /*! return list of selected HDF item names */ const QStringList HDFOptionsWidget::selectedHDFNames() const { QStringList names; // the data link is saved in the second column for (auto* item: ui.twContent->selectedItems()) names << item->text(1); return names; } diff --git a/src/kdefrontend/datasources/NetCDFOptionsWidget.cpp b/src/kdefrontend/datasources/NetCDFOptionsWidget.cpp index ec7031668..7b00506a2 100644 --- a/src/kdefrontend/datasources/NetCDFOptionsWidget.cpp +++ b/src/kdefrontend/datasources/NetCDFOptionsWidget.cpp @@ -1,126 +1,127 @@ /*************************************************************************** File : NetCDFOptionsWidget.cpp Project : LabPlot Description : widget providing options for the import of NetCDF data -------------------------------------------------------------------- Copyright : (C) 2015-2017 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 "NetCDFOptionsWidget.h" #include "ImportFileWidget.h" #include "backend/datasources/filters/NetCDFFilter.h" #include "backend/lib/macros.h" /*! \class NetCDFOptionsWidget \brief Widget providing options for the import of NetCDF data \ingroup kdefrontend */ NetCDFOptionsWidget::NetCDFOptionsWidget(QWidget* parent, ImportFileWidget* fileWidget) : QWidget(parent), m_fileWidget(fileWidget) { ui.setupUi(parent); QStringList headers; headers << i18n("Name") << i18n("Type") << i18n("Properties") << i18n("Values"); ui.twContent->setHeaderLabels(headers); // type column is hidden ui.twContent->hideColumn(1); ui.twContent->setSelectionMode(QAbstractItemView::ExtendedSelection); ui.twContent->setAlternatingRowColors(true); + ui.twContent->header()->setSectionResizeMode(QHeaderView::ResizeToContents); ui.twPreview->setEditTriggers(QAbstractItemView::NoEditTriggers); ui.bRefreshPreview->setIcon( QIcon::fromTheme("view-refresh") ); connect( ui.twContent, SIGNAL(itemSelectionChanged()), SLOT(netcdfTreeWidgetSelectionChanged()) ); connect( ui.bRefreshPreview, SIGNAL(clicked()), fileWidget, SLOT(refreshPreview()) ); } void NetCDFOptionsWidget::clear() { ui.twContent->clear(); ui.twPreview->clear(); } void NetCDFOptionsWidget::updateContent(NetCDFFilter *filter, const QString& fileName) { ui.twContent->clear(); QTreeWidgetItem *rootItem = ui.twContent->invisibleRootItem(); filter->parse(fileName, rootItem); ui.twContent->insertTopLevelItem(0, rootItem); ui.twContent->expandAll(); ui.twContent->resizeColumnToContents(0); ui.twContent->resizeColumnToContents(2); } /*! updates the selected var name of a NetCDF file when the tree widget item is selected */ void NetCDFOptionsWidget::netcdfTreeWidgetSelectionChanged() { DEBUG("netcdfTreeWidgetSelectionChanged()"); QDEBUG("SELECTED ITEMS =" << ui.twContent->selectedItems()); if (ui.twContent->selectedItems().isEmpty()) return; QTreeWidgetItem* item = ui.twContent->selectedItems().first(); if (item->data(1, Qt::DisplayRole).toString() == "variable") m_fileWidget->refreshPreview(); else if (item->data(1, Qt::DisplayRole).toString().contains("attribute")) { // reads attributes (only for preview) NetCDFFilter *filter = (NetCDFFilter *)m_fileWidget->currentFileFilter(); QString fileName = m_fileWidget->ui.leFileName->text(); QString name = item->data(0, Qt::DisplayRole).toString(); QString varName = item->data(1, Qt::DisplayRole).toString().split(' ')[0]; QDEBUG("name =" << name << "varName =" << varName); QString importedText = filter->readAttribute(fileName, name, varName); DEBUG("importedText =" << importedText.toStdString()); QStringList lineStrings = importedText.split('\n'); int rows = lineStrings.size(); ui.twPreview->setRowCount(rows); ui.twPreview->setColumnCount(0); for (int i = 0; i < rows; i++) { QStringList lineString = lineStrings[i].split(' '); int cols = lineString.size(); if (ui.twPreview->columnCount() < cols) ui.twPreview->setColumnCount(cols); for (int j = 0; j < cols; j++) { QTableWidgetItem* item = new QTableWidgetItem(); item->setText(lineString[j]); ui.twPreview->setItem(i, j, item); } } } else DEBUG("non showable object selected in NetCDF tree widget"); } /*! return list of selected NetCDF item names */ const QStringList NetCDFOptionsWidget::selectedNetCDFNames() const { QStringList names; for (auto* item: ui.twContent->selectedItems()) names << item->text(0); return names; } diff --git a/src/kdefrontend/ui/datasources/fitsoptionswidget.ui b/src/kdefrontend/ui/datasources/fitsoptionswidget.ui index 9e1912d93..319423848 100644 --- a/src/kdefrontend/ui/datasources/fitsoptionswidget.ui +++ b/src/kdefrontend/ui/datasources/fitsoptionswidget.ui @@ -1,61 +1,64 @@ FITSOptionsWidget 0 0 - 399 + 492 250 Number of rows to preview: 10000 100 Refresh Qt::Horizontal + + false + 1 diff --git a/src/kdefrontend/ui/datasources/hdfoptionswidget.ui b/src/kdefrontend/ui/datasources/hdfoptionswidget.ui index 8dd88c27c..990ff808e 100644 --- a/src/kdefrontend/ui/datasources/hdfoptionswidget.ui +++ b/src/kdefrontend/ui/datasources/hdfoptionswidget.ui @@ -1,95 +1,98 @@ HDFOptionsWidget 0 0 - 399 + 500 250 Refresh Qt::Horizontal 40 20 Number of rows to preview: 1 10000 100 Qt::Horizontal Shows the content of a HDF file + + false + 1 false false diff --git a/src/kdefrontend/ui/datasources/netcdfoptionswidget.ui b/src/kdefrontend/ui/datasources/netcdfoptionswidget.ui index 40ba79f37..5cad77339 100644 --- a/src/kdefrontend/ui/datasources/netcdfoptionswidget.ui +++ b/src/kdefrontend/ui/datasources/netcdfoptionswidget.ui @@ -1,95 +1,98 @@ NetCDFOptionsWidget 0 0 - 412 + 500 263 Qt::Horizontal Shows the content of a NetCDF file + + false + 1 false false Number of rows to preview: Qt::Horizontal 40 20 1 10000 100 Refresh