356 lines
8.6 KiB
C++
356 lines
8.6 KiB
C++
#include "graph.h"
|
|
#include <qapplication.h>
|
|
#include <qvariant.h>
|
|
#include <qdialog.h>
|
|
#include <qpushbutton.h>
|
|
#include <qcheckbox.h>
|
|
#include <qlabel.h>
|
|
#include <qlineedit.h>
|
|
#include <qlayout.h>
|
|
#include <qtooltip.h>
|
|
#include <qwhatsthis.h>
|
|
#include <qpixmap.h>
|
|
#include <qimage.h>
|
|
#include <stdio.h>
|
|
#include <qpixmap.h>
|
|
#include <qvalidator.h>
|
|
#include <math.h>
|
|
#include <qtimer.h>
|
|
#include <qdatetime.h>
|
|
#include <qcombobox.h>
|
|
#include <qsplitter.h>
|
|
#include <qsizepolicy.h>
|
|
#include <stdlib.h>
|
|
#include "seaset.h"
|
|
#include "utils.h"
|
|
|
|
static char *xZoomPix[] = {
|
|
"16 16 2 1",
|
|
" c None",
|
|
"X c #000000",
|
|
" ",
|
|
" ",
|
|
" X X ",
|
|
" XX XX ",
|
|
" XX XX ",
|
|
" XX XX ",
|
|
" XX XX ",
|
|
" XX XX ",
|
|
" XX XX ",
|
|
" XX XX ",
|
|
" XX XX ",
|
|
" XX XX ",
|
|
" XX XX ",
|
|
" X X ",
|
|
" ",
|
|
" "
|
|
};
|
|
|
|
static char *leftPix[] = {
|
|
"16 16 2 1",
|
|
" c None",
|
|
"X c #000000",
|
|
" ",
|
|
" ",
|
|
" X ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" X ",
|
|
" ",
|
|
" "
|
|
};
|
|
|
|
static char *rightPix[] = {
|
|
"16 16 2 1",
|
|
" c None",
|
|
"X c #000000",
|
|
" ",
|
|
" ",
|
|
" X ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" XX ",
|
|
" X ",
|
|
" ",
|
|
" "
|
|
};
|
|
|
|
static char *undoPix[] = {
|
|
"16 16 2 1",
|
|
" c None",
|
|
"X c #000000",
|
|
" ",
|
|
" XXXXXXXXX ",
|
|
" XX ",
|
|
" XX ",
|
|
" X ",
|
|
" X ",
|
|
" X ",
|
|
" X X ",
|
|
" XX XX ",
|
|
" XX XX ",
|
|
" XXXXXXXXXXXX ",
|
|
" XX ",
|
|
" XX ",
|
|
" X ",
|
|
" ",
|
|
" "
|
|
};
|
|
|
|
Graph::Graph(const char* arg, QWidget *parent, long range)
|
|
: QWidget(parent, 0)
|
|
{
|
|
QPixmap pmOut((const char **)xZoomPix);
|
|
QPixmap pmLeft((const char **)leftPix);
|
|
QPixmap pmRight((const char **)rightPix);
|
|
QPixmap pmUndo((const char **)undoPix);
|
|
QString str;
|
|
//QHBox *buttonBar;
|
|
QPushButton* buttonOk;
|
|
QPushButton* buttonAll;
|
|
QPushButton* buttonUndo;
|
|
QPushButton* buttonLeft;
|
|
QPushButton* buttonOut;
|
|
QPushButton* buttonRight;
|
|
QPushButton* buttonSettings;
|
|
QPushButton* buttonXY;
|
|
QSplitter *graphSplit;
|
|
QVBoxLayout* graphLayout;
|
|
QHBoxLayout* buttonLayout;
|
|
int w,h;
|
|
const char * vars;
|
|
|
|
setName("Graph");
|
|
|
|
graphLayout = new QVBoxLayout(this, 0, 0, "graphLayout");
|
|
|
|
graphSplit = new QSplitter(Qt::Vertical, this, "splitter");
|
|
graphLayout->add(graphSplit);
|
|
|
|
buttonLayout = new QHBoxLayout(0, 6, 2, "buttonBar");
|
|
graphLayout->addLayout(buttonLayout);
|
|
|
|
buttonLayout->addWidget(new QLabel("Range", this));
|
|
|
|
lineEditRange = new QComboBox(true, this);
|
|
//SetLength(lineEditRange, 5, 6);
|
|
buttonLayout->addWidget(lineEditRange);
|
|
QToolTip::add(lineEditRange, "enter a number and m,h or d");
|
|
|
|
buttonOk = new QPushButton(this);
|
|
buttonOk->setDefault(true);
|
|
buttonOk->setText("OK");
|
|
ShrinkButton(buttonOk);
|
|
buttonLayout->addWidget(buttonOk);
|
|
|
|
buttonSettings = new QPushButton(this);
|
|
buttonSettings->setText("Settings");
|
|
ShrinkButton(buttonSettings);
|
|
buttonLayout->addWidget(buttonSettings);
|
|
QToolTip::add(buttonSettings, "edit shown curves");
|
|
|
|
buttonAll = new QPushButton(this);
|
|
buttonAll->setText("Show All");
|
|
ShrinkButton(buttonAll);
|
|
buttonLayout->addWidget(buttonAll);
|
|
QToolTip::add(buttonAll, "show all curves");
|
|
|
|
buttonXY = new QPushButton(this);
|
|
buttonXY->setText("export");
|
|
ShrinkButton(buttonXY);
|
|
buttonLayout->addWidget(buttonXY);
|
|
QToolTip::add(buttonXY, "export data");
|
|
|
|
liveBox = new QCheckBox(this);
|
|
liveBox->setText("live mode");
|
|
buttonLayout->addWidget(liveBox);
|
|
liveBox->setChecked(false);
|
|
|
|
buttonLayout->addStretch(1);
|
|
|
|
buttonUndo = new QPushButton(this);
|
|
buttonUndo->setPixmap(pmUndo);
|
|
w = QMAX(22, buttonUndo->sizeHint().width() - 6);
|
|
h = QMAX(22, buttonUndo->sizeHint().height() - 6);
|
|
if (w > h) { // Mac like
|
|
h += 6;
|
|
w -= 6;
|
|
}
|
|
buttonUndo->setFixedSize(w, h);
|
|
buttonLayout->addWidget(buttonUndo);
|
|
buttonUndo->setEnabled(false);
|
|
QToolTip::add(buttonUndo, "undo zoom or shift action");
|
|
|
|
buttonLeft = new QPushButton(this);
|
|
buttonLeft->setPixmap(pmLeft);
|
|
buttonLeft->setFixedSize(w, h);
|
|
buttonLayout->addWidget(buttonLeft);
|
|
QToolTip::add(buttonLeft, "scroll left");
|
|
|
|
buttonRight = new QPushButton(this);
|
|
buttonRight->setPixmap(pmRight);
|
|
buttonRight->setFixedSize(w, h);
|
|
buttonLayout->addWidget(buttonRight);
|
|
QToolTip::add(buttonRight, "scroll right");
|
|
|
|
buttonOut = new QPushButton(this);
|
|
buttonOut->setPixmap(pmOut);
|
|
buttonOut->setFixedSize(w, h);
|
|
buttonLayout->addWidget(buttonOut);
|
|
QToolTip::add(buttonOut, "zoom out horizontally");
|
|
|
|
str="Sea ";
|
|
str.append(arg);
|
|
topLevelWidget()->setCaption(str);
|
|
|
|
clearWState(WState_Polished);
|
|
|
|
unit='m';
|
|
str="30m";
|
|
|
|
set = new SeaSet(graphSplit, range, "seaset");
|
|
|
|
const char *items[]={
|
|
"1m","2m","5m","10m","15m","30m"
|
|
,"1h","2h","4h","8h","16h"
|
|
,"1d","2d","4d","8d",0};
|
|
lineEditRange->insertStrList(items);
|
|
lineEditRange->setSizeLimit(15);
|
|
lineEditRange->setMaxCount(15);
|
|
lineEditRange->setEditText(str);
|
|
lineEditRange->lineEdit()->selectAll();
|
|
|
|
connect(lineEditRange, SIGNAL(activated(int)),
|
|
this, SLOT(activateRange()));
|
|
connect(buttonOk, SIGNAL(clicked()),
|
|
this, SLOT(activateRange()));
|
|
connect(buttonAll, SIGNAL(clicked()),
|
|
set, SLOT(showAll()));
|
|
connect(buttonSettings, SIGNAL(clicked()),
|
|
this, SIGNAL(gotoSettings()));
|
|
connect(buttonXY, SIGNAL(clicked()),
|
|
this, SIGNAL(openExport()));
|
|
connect(buttonUndo, SIGNAL(clicked()),
|
|
set, SLOT(undoZoom()));
|
|
connect(buttonLeft, SIGNAL(clicked()),
|
|
set, SLOT(shiftLeft()));
|
|
connect(buttonOut, SIGNAL(clicked()),
|
|
set, SLOT(zoomOutX()));
|
|
connect(buttonRight, SIGNAL(clicked()),
|
|
set, SLOT(shiftRight()));
|
|
connect(liveBox, SIGNAL(toggled(bool)),
|
|
set, SLOT(setLive(bool)));
|
|
connect(set, SIGNAL(undoEnabled(bool)),
|
|
buttonUndo, SLOT(setEnabled(bool)));
|
|
connect(lineEditRange->lineEdit(), SIGNAL(textChanged(const QString &)),
|
|
this, SLOT(autoReturn(const QString &)));
|
|
|
|
set->setHost(arg);
|
|
|
|
if (printit()) {
|
|
printf("reading curve list,\n");
|
|
}
|
|
if (range < 365*24*3600) {
|
|
vars = "now";
|
|
} else {
|
|
vars = NULL;
|
|
}
|
|
set->autoCurves(vars);
|
|
if (printit()) {
|
|
printf("opening window.\n");
|
|
}
|
|
//lineEditRange->selectAll();
|
|
|
|
|
|
QTimer *timer = new QTimer(this, "repeat");
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(liveUpdate()));
|
|
timer->start(2500);
|
|
}
|
|
|
|
void Graph::liveUpdate() {
|
|
if (isShown() && width() > 3) {
|
|
set->liveUpdate();
|
|
}
|
|
}
|
|
|
|
void Graph::showIt(bool yes) {
|
|
if (yes) {
|
|
set->liveUpdate();
|
|
show();
|
|
} else {
|
|
hide();
|
|
}
|
|
}
|
|
|
|
void Graph::activateRange() {
|
|
long fact;
|
|
QString t;
|
|
double rng;
|
|
unsigned int j;
|
|
|
|
//setFocus();
|
|
t = lineEditRange->currentText();
|
|
for (j = 0; j < t.length(); j++) {
|
|
if (t[j] > '9') {
|
|
unit = t.latin1()[j];
|
|
t.truncate(j);
|
|
break;
|
|
}
|
|
}
|
|
switch (unit) {
|
|
case 'D': unit='d';
|
|
case 'd': fact = 24*3600; break;
|
|
case 'H': unit='h';
|
|
case 'h': fact = 3600; break;
|
|
case 'M': unit='m';
|
|
case 'm': fact = 60; break;
|
|
case 'S': unit='s';
|
|
case 's': fact = 1; break;
|
|
default: fact = 60; unit = 'm';
|
|
}
|
|
rng = t.toDouble() * fact;
|
|
//printf("%s %lf %ld\n", t.latin1(), rng, fact);
|
|
if (rng > SEA_MAX_RANGE) {
|
|
unit = 'd';
|
|
t.sprintf("%d%c", (SEA_MAX_RANGE + 36000) / 24 / 3600, unit);
|
|
lineEditRange->setEditText(t);
|
|
rng = SEA_MAX_RANGE;
|
|
} else if (rng < 59.5) {
|
|
rng = 60;
|
|
if (unit == 's') {
|
|
lineEditRange->setEditText("60s");
|
|
} else {
|
|
unit = 'm';
|
|
lineEditRange->setEditText("1m");
|
|
}
|
|
} else {
|
|
t.append(unit);
|
|
lineEditRange->setEditText(t);
|
|
}
|
|
set->rescaleRange(long(rng));
|
|
lineEditRange->lineEdit()->selectAll();
|
|
}
|
|
|
|
void Graph::autoReturn(const QString &text) {
|
|
if (0 == text.find(QRegExp("\\d{1,4}[DdHhMmSs]"))) {
|
|
activateRange();
|
|
} else if (0 == text.find(QRegExp("[Qq]"))) {
|
|
exit(0);
|
|
}
|
|
}
|