! updates the selected var name of a FITS file when the tree widget item is selected */ TODO
| 55 | */ |
| 56 | // TODO |
| 57 | void FITSOptionsWidget::fitsTreeWidgetSelectionChanged() { |
| 58 | QDEBUG(Q_FUNC_INFO << ", SELECTED ITEMS =" << ui.twExtensions->selectedItems()); |
| 59 | |
| 60 | if (ui.twExtensions->selectedItems().isEmpty()) |
| 61 | return; |
| 62 | |
| 63 | QTreeWidgetItem* item = ui.twExtensions->selectedItems().first(); |
| 64 | int column = ui.twExtensions->currentColumn(); |
| 65 | |
| 66 | WAIT_CURSOR; |
| 67 | const QString& itemText = item->text(column); |
| 68 | QString selectedExtension; |
| 69 | // TODO: same as extensionName() ? |
| 70 | int extType = 0; |
| 71 | if (itemText.contains(QLatin1String("IMAGE #")) || itemText.contains(QLatin1String("ASCII_TBL #")) || itemText.contains(QLatin1String("BINARY_TBL #"))) |
| 72 | extType = 1; |
| 73 | else if (!itemText.compare(i18n("Primary header"))) |
| 74 | extType = 2; |
| 75 | if (extType == 0) { |
| 76 | if (item->parent() != nullptr) { |
| 77 | if (item->parent()->parent() != nullptr) |
| 78 | selectedExtension = item->parent()->parent()->text(0) + QStringLiteral("[") + item->text(column) + QStringLiteral("]"); |
| 79 | } |
| 80 | } else if (extType == 1) { |
| 81 | if (item->parent() != nullptr) { |
| 82 | if (item->parent()->parent() != nullptr) { |
| 83 | bool ok; |
| 84 | int hduNum = itemText.right(1).toInt(&ok); |
| 85 | selectedExtension = item->parent()->parent()->text(0) + QStringLiteral("[") + QString::number(hduNum - 1) + QStringLiteral("]"); |
| 86 | } |
| 87 | } |
| 88 | } else { |
| 89 | if (item->parent()->parent() != nullptr) |
| 90 | selectedExtension = item->parent()->parent()->text(column); |
| 91 | } |
| 92 | |
| 93 | if (!selectedExtension.isEmpty()) { |
| 94 | auto filter = static_cast<FITSFilter*>(m_fileWidget->currentFileFilter()); |
| 95 | bool readFitsTableToMatrix; |
| 96 | const QVector<QStringList> importedStrings = filter->readChdu(selectedExtension, &readFitsTableToMatrix, ui.sbPreviewLines->value()); |
| 97 | Q_EMIT m_fileWidget->enableImportToMatrix(readFitsTableToMatrix); |
| 98 | |
| 99 | const int rows = importedStrings.size(); |
| 100 | ui.twPreview->clear(); |
| 101 | |
| 102 | ui.twPreview->setRowCount(rows); |
| 103 | const int maxColumns = 300; |
| 104 | for (int i = 0; i < rows; ++i) { |
| 105 | QStringList lineString = importedStrings[i]; |
| 106 | int colCount; |
| 107 | if (i == 0) { |
| 108 | colCount = lineString.size() > maxColumns ? maxColumns : lineString.size(); |
| 109 | ui.twPreview->setColumnCount(colCount); |
| 110 | } |
| 111 | colCount = lineString.size() > maxColumns ? maxColumns : lineString.size(); |
| 112 | |
| 113 | for (int j = 0; j < colCount; ++j) { |
| 114 | auto* item = new QTableWidgetItem(lineString[j]); |
nothing calls this directly
no test coverage detected