00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <iostream>
00010 #include <QMessageBox>
00011 #include <QFileDialog>
00012 #include <QString>
00013 #include "skymap.h"
00014 #include "healpixmap.h"
00015 #include "selectedpixelmodel.h"
00016 #include "controldialog.h"
00017
00018 using namespace std;
00019
00020
00021
00022
00023
00024
00025
00026
00027 ControlDialog::ControlDialog(QWidget *parent) : QDialog(parent)
00028 {
00029 setupUi(this);
00030 range->setVisible(true);
00031 pixlistview->setModel(&selectedpixels);
00032 clearSelection = pixlistview->selectionModel();
00033
00034 connect(
00035 clearSelection, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
00036 this, SLOT(updateClearSelection(const QItemSelection &, const QItemSelection &))
00037 );
00038
00039 connect( pixlistview, SIGNAL(doubleClicked(const QModelIndex &) ),
00040 this, SLOT( doubleClicked(const QModelIndex &) ));
00041
00042 pixstatslistview->setModel(&statspixels);
00043 statslistview->setModel(&mapstats);
00044
00045 };
00046
00047
00048
00049
00050
00051
00052 void ControlDialog::clearStatus()
00053 {
00054 loading->setText("Waiting");
00055 filename->clear();
00056 nside->setText("Nside: --");
00057 ordering->setText("Ordering: --");
00058 mapstats.asStatus();
00059 return;
00060 }
00061
00062
00063
00064
00065
00066
00067
00068 void ControlDialog::startFile(QString fname)
00069 {
00070 clearStatus();
00071 loading->setText("Loading");
00072 filename->setText(fname);
00073
00074 };
00075 void ControlDialog::loadFile(const char *fname)
00076 {
00077 loadFile(QString(fname));
00078 }
00079 void ControlDialog::loadFile(QString fname)
00080 {
00081 startFile( fname );
00082 }
00083
00084 void ControlDialog::hasField(Field f, bool b)
00085 {
00086 mapstats.hasField(f, b);
00087 return;
00088 }
00089 void ControlDialog::loadField(Field f)
00090 {
00091 mapstats.loadField(f);
00092 return;
00093 }
00094 void ControlDialog::loadNSide(int ns, int ord)
00095 {
00096 QString str;
00097 nside->setText(QString("Nside: %1;").arg(ns));
00098 ordering->setText(str.fromAscii((ord == 2) ? "Ordering: RING" : "Ordering: NESTED"));
00099 }
00100
00101
00102
00103
00104
00105 void ControlDialog::finished(Skymap *m)
00106 {
00107 mapstats.asStats(m);
00108
00109 return;
00110 }
00111
00112
00113 void ControlDialog::init(Skymap *map)
00114 {
00115 range->init(map);
00116
00117 selectedpixels.set(map);
00118 statspixels.asStats(&selectedpixels);
00119
00120 for(int i = 0; i < selectedpixels.columnCount(); i++) {
00121 pixlistview->setColumnWidth(i,85);
00122 pixstatslistview->setColumnWidth(i,85);
00123 }
00124 clearsel->setEnabled(false);
00125 clearall->setEnabled(false);
00126 savelist->setEnabled(false);
00127 return;
00128 }
00129
00130 bool ControlDialog::selectPixel(int i, BasePixel *pix)
00131 {
00132 bool set = selectedpixels(i,pix);
00133 clearall->setEnabled(selectedpixels.rowCount() > 0);
00134 savelist->setEnabled(selectedpixels.rowCount() > 0);
00135 statspixels.updateStats();
00136 return set;
00137 }
00138
00139
00140 void ControlDialog::on_clearsel_clicked()
00141 {
00142 QModelIndexList indexes = clearSelection->selectedIndexes();
00143 QModelIndex index;
00144
00145
00146 vector<int> clearpixs;
00147 foreach(index, indexes) {
00148 if( index.column() == 0 )
00149 clearpixs.push_back(selectedpixels.pixnum(index.row()));
00150 }
00151
00152 BasePixel dummy;
00153 for(uint i = 0; i < clearpixs.size(); i++)
00154 selectPixel(clearpixs[i],&dummy);
00155 clearsel->setEnabled(false);
00156
00157 emit resetPixels(clearpixs);
00158 return;
00159 }
00160
00161 void ControlDialog::on_clearall_clicked()
00162 {
00163 vector<int> clearpixs(selectedpixels.size());
00164 for(int i = 0; i < selectedpixels.size(); i++)
00165 clearpixs[i] = selectedpixels.pixnum(i);
00166 selectedpixels.clear();
00167 clearsel->setEnabled(false);
00168 clearall->setEnabled(false);
00169 savelist->setEnabled(false);
00170 emit resetPixels(clearpixs);
00171 }
00172
00173 void ControlDialog::on_savelist_clicked()
00174 {
00175 QString fname = QFileDialog::getSaveFileName(this,
00176 tr("Save Pixel List"), tr("."), tr("*"));
00177 if (fname.isEmpty()) return;
00178 selectedpixels.writeListToFile(fname);
00179 }
00180
00181 void ControlDialog::updateClearSelection(const QItemSelection& , const QItemSelection& )
00182 {
00183 clearsel->setEnabled( clearSelection->selectedIndexes().size() > 0 );
00184 }
00185
00186
00187
00188 void ControlDialog::doubleClicked(const QModelIndex & index )
00189 {
00190 QModelIndex idx = selectedpixels.index(index.row(),0);
00191 emit recenterOnPixel(selectedpixels.data(idx,Qt::DisplayRole).toInt());
00192 return;
00193 }