00001
00014 #include <math.h>
00015
00016 #include <kapp.h>
00017 #include <klocale.h>
00018 #include <kmessagebox.h>
00019
00020 #include <qheader.h>
00021 #include <qpushbutton.h>
00022 #include <qpainter.h>
00023
00024 #include "skymap.h"
00025 #include "datainfo.h"
00026 #include "setiloc.h"
00027 #include "ksetiwatch.h"
00028
00029
00030 QString DataInfoListViewItem::key(int column, bool) const
00031 {
00032
00033 static QString ret;
00034 QString val;
00035 double tmp;
00036
00037 if(column == 4)
00038 {
00039 val = text(column);
00040 tmp = val.toDouble();
00041 val.sprintf("%f", tmp);
00042 ret = val.rightJustify(12, '0');
00043 }
00044 else
00045 {
00046 ret = text(column);
00047 }
00048
00049 return(ret);
00050 }
00051
00052
00053
00054 DataInfo::DataInfo(QWidget* parent, const char* name) : QWidget(parent,name)
00055 {
00056 Ksetiwatch::TableColumn ditc[] =
00057 {
00058 {i18n("Location"), 60, AlignLeft},
00059 {i18n("From"), 170, AlignRight},
00060 {i18n("Recorded On"), 170, AlignRight},
00061 {i18n("Source"), 120, AlignRight},
00062 {i18n("Base Frequency"), 100, AlignLeft},
00063 {i18n("Angle Range"), 100, AlignRight},
00064 {i18n("TeraFlops"), 80, AlignRight}
00065 };
00066
00067 QListView_1= new popListView(this);
00068 QListView_1->setShowSortIndicator(false);
00069 QListView_1->setPopupStyle(popListView::ShowAnywhere);
00070 QListView_1->move(5,1);
00071
00072 for(int i=0; i<(int)(sizeof(ditc)/sizeof(ditc[0])); i++)
00073 {
00074 QListView_1->addColumn(ditc[i].text,-1);
00075 QListView_1->setColumnWidth(i, ditc[i].width);
00076 QListView_1->setColumnAlignment(i, ditc[i].alignment);
00077 }
00078
00079 QPushButton_1= new QPushButton(this);
00080 QPushButton_1->move(10,100);
00081 QPushButton_1->setText(i18n("Sky Map"));
00082 QPushButton_1->setMinimumSize(QPushButton_1->sizeHint().width(), 25);
00083 QPushButton_1->resize(QPushButton_1->sizeHint());
00084 connect(QPushButton_1, SIGNAL(clicked()), SLOT(showMap()));
00085
00086 connect(QListView_1->header(), SIGNAL(sectionClicked(int)),
00087 this, SLOT(toggleSorting(int)));
00088 sortingorder = true;
00089
00090 lvDict.setAutoDelete(true);
00091
00092 refreshList();
00093 }
00094
00095
00096 DataInfo::~DataInfo()
00097 {
00098 }
00099
00100
00101 void DataInfo::resizeEvent(QResizeEvent*)
00102 {
00103 QListView_1->resize(this->width()-10,
00104 this->height()-QPushButton_1->height()-5);
00105 QPushButton_1->move(5, QListView_1->y()+QListView_1->height()+2);
00106 }
00107
00108
00109 void DataInfo::paintEvent(QPaintEvent* e)
00110 {
00111 QListView_1->setGridEnabled(globalopts->DrawGrid);
00112 QWidget::paintEvent(e);
00113 }
00114
00115
00116 void DataInfo::refreshList()
00117 {
00118 SetiLoc *loc;
00119
00120 for(loc=Ksetiwatch::locationList().first(); loc != 0;
00121 loc=Ksetiwatch::locationList().next())
00122 {
00123 DataInfoListViewItem* it = lvDict[loc->id()];
00124 if(it == 0)
00125 slotUpdateList(loc, Ksetiwatch::ListAdd);
00126 else
00127 refreshListItem(loc, it);
00128 }
00129 }
00130
00131
00132 void DataInfo::slotUpdateList(SetiLoc* loc, int type)
00133 {
00134 DataInfoListViewItem* it;
00135
00136 switch(type)
00137 {
00138 case Ksetiwatch::ListAdd:
00139 {
00140 it = new DataInfoListViewItem(QListView_1);
00141 if(it)
00142 {
00143 lvDict.insert(loc->id(), it);
00144 connect(loc, SIGNAL(updatedWorkUnitData()),
00145 this, SLOT(slotUpdateWorkUnitData()));
00146 refreshListItem(loc, it);
00147 }
00148 break;
00149 }
00150 case Ksetiwatch::ListEdit:
00151 {
00152 refreshListItem(loc);
00153 break;
00154 }
00155 case Ksetiwatch::ListDelete:
00156 {
00157 disconnect(loc, SIGNAL(updatedWorkUnitData()),
00158 this, SLOT(slotUpdateWorkUnitData()));
00159 lvDict.remove(loc->id());
00160 break;
00161 }
00162 }
00163 }
00164
00165
00166 void DataInfo::refreshListItem(SetiLoc* loc, DataInfoListViewItem* it)
00167 {
00168 QString val;
00169
00170 if(loc && it == 0)
00171 it = lvDict[loc->id()];
00172 if(loc && it)
00173 {
00174 it->setText(ColLocation, loc->description());
00175 if(loc->exists(SetiLoc::SC_WorkUnitFile))
00176 {
00177 double ra = loc->startRA();
00178 double dec = loc->startDec();
00179 val = loc->convertRAToString(ra) + " RA ";
00180 if(dec >= 0.0) val += "+ "; else val += "- ";
00181 val += loc->convertDecToString(fabs(dec)) + " Dec";
00182 it->setText(ColFrom, val);
00183 it->setText(ColRecordedOn, loc->timeRecordedString());
00184 if(loc->receiver() == "ao1420")
00185 it->setText(ColSource, i18n("Arecibo Telescope "));
00186 else
00187 it->setText(ColSource, QString::null);
00188 it->setText(ColBaseFreq, (QString(" %1 GHz")).arg(loc->baseFrequency(), 0, 'f', 9));
00189 it->setText(ColAngleRange, QString::number(loc->angleRange()));
00190 it->setText(ColTeraFlops, val.setNum(loc->teraFlops(loc->angleRange()), 'f', 4));
00191 }
00192 else
00193 {
00194 it->setText(ColFrom, QString::null);
00195 it->setText(ColRecordedOn, QString::null);
00196 it->setText(ColSource, QString::null);
00197 it->setText(ColBaseFreq, QString::null);
00198 it->setText(ColAngleRange, QString::null);
00199 it->setText(ColTeraFlops, QString::null);
00200 }
00201 }
00202 }
00203
00204
00205 void DataInfo::showMap()
00206 {
00207 SkyMap* map = SkyMap::showMap();
00208
00209 if(map)
00210 {
00211 map->clearMap();
00212 for(SetiLoc *loc=Ksetiwatch::locationList().first(); loc != 0;
00213 loc=Ksetiwatch::locationList().next() )
00214 {
00215 map->addLocation(loc);
00216 }
00217 map->repaint();
00218 }
00219 }
00220
00221
00222 void DataInfo::toggleSorting(int column)
00223 {
00224 sortingorder = !sortingorder;
00225 QListView_1->setSorting(column, sortingorder);
00226 }
00227
00228
00229 void DataInfo::slotUpdateWorkUnitData()
00230 {
00231 SetiLoc* loc = (SetiLoc*)(sender());
00232
00233 if(loc)
00234 refreshListItem(loc);
00235 }
00236
00237 #include "datainfo.moc"
00238