|
27 | 27 | #include <QListWidget>
|
28 | 28 | #include <QMessageBox>
|
29 | 29 | #include <QtGlobal>
|
| 30 | +#include <QTableWidget> |
| 31 | +#include <QTableWidgetItem> |
| 32 | +#include <QHeaderView> |
30 | 33 |
|
31 | 34 | #include <application.h>
|
32 | 35 | #include <flipwidget.h>
|
@@ -140,6 +143,7 @@ MainWindow::MainWindow(const QString& fits_filename, QWidget *parent):
|
140 | 143 | file_open_here_action->setShortcut(QKeySequence::Open);
|
141 | 144 | auto file_open_action = file_menu->addAction(tr("&Open in new window"), Application::instance(), SLOT(openFile(void)));
|
142 | 145 | file_open_action->setShortcut(tr("ctrl+shift+o"));
|
| 146 | + file_menu->addAction(tr("View &headers"), this, SLOT(viewHeaders())); |
143 | 147 | auto file_close_action = file_menu->addAction(tr("&Close"), this, SLOT(close()));
|
144 | 148 | file_close_action->setShortcut(QKeySequence::Close);
|
145 | 149 | file_menu->addSeparator();
|
@@ -272,6 +276,31 @@ void MainWindow::openFileHere() {
|
272 | 276 | }
|
273 | 277 | }
|
274 | 278 |
|
| 279 | +void MainWindow::viewHeaders() { |
| 280 | + auto& header_unit = state_->fits().header_unit(); |
| 281 | + auto size = header_unit.size(); |
| 282 | + |
| 283 | + std::unique_ptr<QDialog> headers_dialog(new QDialog(this, Qt::WindowCloseButtonHint)); |
| 284 | + headers_dialog->setWindowTitle(QString("Headers for ") + QFileInfo(state_->filename()).fileName()); |
| 285 | + |
| 286 | + auto table = new QTableWidget(size, 2); |
| 287 | + Q_ASSERT(table->rowCount() == size); |
| 288 | + table->setHorizontalHeaderLabels(QStringList() << "Key" << "Value"); |
| 289 | + table->setEditTriggers(QTableWidget::NoEditTriggers); |
| 290 | + table->horizontalHeader()->setStretchLastSection(true); |
| 291 | + |
| 292 | + auto iter = header_unit.cbegin(); |
| 293 | + for (int i = 0; i < table->rowCount() && iter != header_unit.cend(); ++i, ++iter) { |
| 294 | + table->setItem(i, 0, new QTableWidgetItem(iter->first)); |
| 295 | + table->setItem(i, 1, new QTableWidgetItem(iter->second)); |
| 296 | + } |
| 297 | + |
| 298 | + auto layout = new QBoxLayout(QBoxLayout::LeftToRight, headers_dialog.get()); |
| 299 | + layout->addWidget(table); |
| 300 | + headers_dialog->setLayout(layout); |
| 301 | + headers_dialog->exec(); |
| 302 | +} |
| 303 | + |
275 | 304 | void MainWindow::refresh() {
|
276 | 305 | try {
|
277 | 306 | setState(new MainWindowState{state_->filename(), state_->isWatched()});
|
|
0 commit comments