Beispiel #1
0
FlowViewWindow::FlowViewWindow(const QVector<CANFrame> *frames, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::FlowViewWindow)
{
    ui->setupUi(this);    

    readSettings();

    modelFrames = frames;

    playbackTimer = new QTimer();

    currentPosition = 0;
    playbackActive = false;
    playbackForward = true;

    memset(refBytes, 0, 8);
    memset(currBytes, 0, 8);
    memset(triggerValues, -1, sizeof(int) * 8);

    //ui->graphView->setInteractions();

    ui->graphView->xAxis->setRange(0, 8);
    ui->graphView->yAxis->setRange(-10, 265); //run range a bit outside possible number so they aren't plotted in a hard to see place
    ui->graphView->axisRect()->setupFullAxesBox();

    QCPItemText *textLabel = new QCPItemText(ui->graphView);
    ui->graphView->addItem(textLabel);
    textLabel->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter);
    textLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
    textLabel->position->setCoords(0.5, .5);
    textLabel->setText("+");
    textLabel->setFont(QFont(font().family(), 16)); // make font a bit larger
    textLabel->setPen(QPen(Qt::black)); // show black border around text

    ui->graphView->xAxis->setLabel("Time Axis");
    ui->graphView->yAxis->setLabel("Value Axis");
    QFont legendFont = font();
    legendFont.setPointSize(10);
    QFont legendSelectedFont = font();
    legendSelectedFont.setPointSize(12);
    legendSelectedFont.setBold(true);
    ui->graphView->legend->setFont(legendFont);
    ui->graphView->legend->setSelectedFont(legendSelectedFont);
    ui->graphView->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items
    //ui->graphView->xAxis->setAutoSubTicks(false);
    //ui->graphView->xAxis->setAutoTicks(false);
    ui->graphView->xAxis->setAutoTickStep(false);
    ui->graphView->xAxis->setAutoSubTicks(false);
    ui->graphView->xAxis->setNumberFormat("gb");
    ui->graphView->xAxis->setTickStep(5.0);
    ui->graphView->xAxis->setSubTickCount(0);

    connect(ui->btnBackOne, SIGNAL(clicked(bool)), this, SLOT(btnBackOneClick()));
    connect(ui->btnPause, SIGNAL(clicked(bool)), this, SLOT(btnPauseClick()));
    connect(ui->btnReverse, SIGNAL(clicked(bool)), this, SLOT(btnReverseClick()));
    connect(ui->btnStop, SIGNAL(clicked(bool)), this, SLOT(btnStopClick()));
    connect(ui->btnPlay, SIGNAL(clicked(bool)), this, SLOT(btnPlayClick()));
    connect(ui->btnForwardOne, SIGNAL(clicked(bool)), this, SLOT(btnFwdOneClick()));
    connect(ui->spinPlayback, SIGNAL(valueChanged(int)), this, SLOT(changePlaybackSpeed(int)));
    connect(ui->cbLoopPlayback, SIGNAL(clicked(bool)), this, SLOT(changeLooping(bool)));
    connect(ui->listFrameID, SIGNAL(currentTextChanged(QString)), this, SLOT(changeID(QString)));
    connect(playbackTimer, SIGNAL(timeout()), this, SLOT(timerTriggered()));    
    connect(ui->graphView, SIGNAL(plottableDoubleClick(QCPAbstractPlottable*,QMouseEvent*)), this, SLOT(plottableDoubleClick(QCPAbstractPlottable*,QMouseEvent*)));
    connect(ui->txtTrigger0, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger1, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger2, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger3, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger4, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger5, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger6, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger7, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));

    connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));

    ui->graphView->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui->graphView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestGraph(QPoint)));
    ui->flowView->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui->flowView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestFlow(QPoint)));

    playbackTimer->setInterval(ui->spinPlayback->value()); //set the timer to the default value of the control
}
void MainWindow::setupItemTracerTest(QCustomPlot *customPlot)
{
	QCPItemTracer *tracer1 = new QCPItemTracer(customPlot);
	customPlot->addItem(tracer1);
	tracer1->position->setCoords(1, 3);
	tracer1->setStyle(QCPItemTracer::tsCircle);
	tracer1->setSize(20);

	QCPItemTracer *tracer2 = new QCPItemTracer(customPlot);
	customPlot->addItem(tracer2);
	tracer2->position->setCoords(2, 2.5);
	tracer2->setStyle(QCPItemTracer::tsCrosshair);

	QCPItemTracer *tracer3 = new QCPItemTracer(customPlot);
	customPlot->addItem(tracer3);
	tracer3->position->setCoords(3, 2);
	tracer3->setStyle(QCPItemTracer::tsPlus);
	tracer3->setSize(20);

	QCPItemTracer *tracer4 = new QCPItemTracer(customPlot);
	customPlot->addItem(tracer4);
	tracer4->position->setCoords(4, 1.5);
	tracer4->setStyle(QCPItemTracer::tsSquare);
	tracer4->setSize(20);

	QCPGraph *graph = customPlot->addGraph();
	int n = 20;
	QVector<double> x(n), y(n);
	for (int i=0; i<n; ++i)
	{
		x[i] = 0.5+i/(double)n*4;
		y[i] = qSin(x[i])+1.5;
	}
	graph->setData(x, y);

	QCPItemTracer *graphTracer = new QCPItemTracer(customPlot);
	customPlot->addItem(graphTracer);
	graphTracer->setGraph(graph);
	graphTracer->setGraphKey(2.3);
	graphTracer->setStyle(QCPItemTracer::tsNone);
	graphTracer->setInterpolating(true);
	tracerTestTracer = graphTracer;
	connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(tracerTestMouseMove(QMouseEvent*)));
	graphTracer->setStyle(QCPItemTracer::tsSquare);

	QCPItemText *text = new QCPItemText(customPlot);
	customPlot->addItem(text);
	text->setText("Tracer");
	text->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
	text->position->setType(QCPItemPosition::ptAxisRectRatio);
	text->position->setCoords(0.5, 0.05);
	text->setPen(QPen());

	QCPItemCurve *curve = new QCPItemCurve(customPlot);
	customPlot->addItem(curve);
	curve->start->setParentAnchor(text->bottom);
	curve->startDir->setParentAnchor(curve->start);
	curve->startDir->setCoords(0, 100);
	curve->end->setParentAnchor(tracerTestTracer->position);
	curve->end->setCoords(0, -5);
	curve->endDir->setParentAnchor(curve->end);
	curve->endDir->setCoords(0, -100);
	curve->setHead(QCPLineEnding::esSpikeArrow);
}