Skip to content

Commit 35a63dd

Browse files
aalexrAlexander Rakitin
authored and
Alexander Rakitin
committed
Implemented FITS header viewer
Added title and made window modalless Reverted dialog behaviour and made some minor fixes
1 parent fca3c03 commit 35a63dd

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

include/fits.h

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ class FITS {
100100
qvariant_cast<T>(it->second) : def);
101101
}
102102

103+
typedef std::map<QString, QString>::const_iterator const_iterator;
104+
105+
const_iterator begin() const { return headers_.cbegin(); }
106+
const_iterator end() const { return headers_.cend(); }
107+
const_iterator cbegin() const { return headers_.cbegin(); }
108+
const_iterator cend() const { return headers_.cend(); }
109+
std::size_t size() const { return headers_.size(); }
110+
103111
inline double bscale() const { return header_as<double>("BSCALE", 1.0); }
104112
inline double bzero() const { return header_as<double>("BZERO", 0.0); }
105113
};

include/mainwindow.h

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class MainWindow:
117117
inline const char* homePageURL() const { return "http://fips.space"; }
118118
public slots:
119119
void openFileHere();
120+
void viewHeaders();
120121
void refresh();
121122
void setAutoRefresh(bool autorefresh);
122123
void zoomIn();

src/mainwindow.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <QListWidget>
2828
#include <QMessageBox>
2929
#include <QtGlobal>
30+
#include <QTableWidget>
31+
#include <QTableWidgetItem>
32+
#include <QHeaderView>
3033

3134
#include <application.h>
3235
#include <flipwidget.h>
@@ -140,6 +143,7 @@ MainWindow::MainWindow(const QString& fits_filename, QWidget *parent):
140143
file_open_here_action->setShortcut(QKeySequence::Open);
141144
auto file_open_action = file_menu->addAction(tr("&Open in new window"), Application::instance(), SLOT(openFile(void)));
142145
file_open_action->setShortcut(tr("ctrl+shift+o"));
146+
file_menu->addAction(tr("View &headers"), this, SLOT(viewHeaders()));
143147
auto file_close_action = file_menu->addAction(tr("&Close"), this, SLOT(close()));
144148
file_close_action->setShortcut(QKeySequence::Close);
145149
file_menu->addSeparator();
@@ -272,6 +276,31 @@ void MainWindow::openFileHere() {
272276
}
273277
}
274278

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+
275304
void MainWindow::refresh() {
276305
try {
277306
setState(new MainWindowState{state_->filename(), state_->isWatched()});

0 commit comments

Comments
 (0)