DrawInteraction::DrawInteraction(QWidget *parent) :
    QCustomPlot(parent)
{
    resize(600,400);

    statusBar = new QStatusBar(this);

    srand(QDateTime::currentDateTime().toTime_t());

    setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
                                      QCP::iSelectLegend | QCP::iSelectPlottables);
    xAxis->setRange(-8, 8);
    yAxis->setRange(-5, 5);
    axisRect()->setupFullAxesBox();

    plotLayout()->insertRow(0);
    plotLayout()->addElement(0, 0, new QCPPlotTitle(this, "Interaction Example"));

    xAxis->setLabel("x Axis");
    yAxis->setLabel("y Axis");
    legend->setVisible(true);
    QFont legendFont = font();
    legendFont.setPointSize(10);
    legend->setFont(legendFont);
    legend->setSelectedFont(legendFont);
    legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items

    addRandomGraph();
    addRandomGraph();
    addRandomGraph();
    addRandomGraph();

    // connect slot that ties some axis selections together (especially opposite axes):
    connect(this, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
    // connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
    connect(this, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
    connect(this, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));

    // make bottom and left axes transfer their ranges to top and right axes:
    connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange)));
    connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange)));

    // connect some interaction slots:
    connect(this, SIGNAL(titleDoubleClick(QMouseEvent*,QCPPlotTitle*)), this, SLOT(titleDoubleClick(QMouseEvent*,QCPPlotTitle*)));
    connect(this, SIGNAL(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)), this, SLOT(axisLabelDoubleClick(QCPAxis*,QCPAxis::SelectablePart)));
    connect(this, SIGNAL(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)), this, SLOT(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*)));

    // connect slot that shows a message in the status bar when a graph is clicked:
    connect(this, SIGNAL(plottableClick(QCPAbstractPlottable*,QMouseEvent*)), this, SLOT(graphClicked(QCPAbstractPlottable*)));

    // setup policy and connect slot for context menu popup:
    setContextMenuPolicy(Qt::CustomContextMenu);
    connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));
}
Exemplo n.º 2
0
void smart_plot::initGraph(QCustomPlot *customPlot)
{
    //Adds axes on the top and right
    customPlot->axisRect()->setupFullAxesBox();

    //Add title
    customPlot->plotLayout()->insertRow(0);
    QCPTextElement *title = new QCPTextElement(customPlot, tr("Open Files to Plot Data"), QFont("sans", 17, QFont::Bold));
    customPlot->plotLayout()->addElement(0, 0, title);

    //Add axes labels
    customPlot->xAxis->setLabel(tr("X Axis"));
    customPlot->yAxis->setLabel(tr("Y Axis"));

    customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
                                    QCP::iSelectLegend | QCP::iSelectPlottables | QCP::iSelectItems | QCP::iMultiSelect);

    connect(customPlot, SIGNAL(selectionChangedByUser()),
            this, SLOT(selectionChanged()));

    connect(customPlot->xAxis,SIGNAL(rangeChanged(QCPRange)),
            this, SLOT(rangeChanged(QCPRange)));

    connect(customPlot, SIGNAL(mousePress(QMouseEvent*)),
            this, SLOT(mousePress(QMouseEvent*)));

    connect(title, SIGNAL(doubleClicked(QMouseEvent*)), this, SLOT(titleDoubleClick(QMouseEvent*)));

    connect(customPlot, SIGNAL(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)),
            this, SLOT(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart)));

    connect(customPlot, SIGNAL(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)),
            this, SLOT(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*)));

    // setup policy and connect slot for context menu popup:
    customPlot->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(customPlot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));

    // make bottom x axis transfer its ranges to top x axis which is used for showing events
    connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));

    axisHandler.setAxisType(customPlot->xAxis, axis_handler::fixed);
    //Short Cuts!
    //Rescale to first selected plot
    //new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_R), this, SLOT(close()));
    //Rescale to first selected plot
    //new QShortcut(Qt::Key_Delete, this, SLOT(selected_remove()));
}
Exemplo n.º 3
0
BodeWidget::BodeWidget(QWidget *parent) :
    QWidget(parent)
{
    QVBoxLayout* plotLayout = new QVBoxLayout(this);

    hue = 250;

    dbPlot = new QCustomPlot(this);
    paPlot = new QCustomPlot(this);

    dbPlot->setInteractions(QCustomPlot::iSelectPlottables | QCustomPlot::iSelectLegend);
    dbPlot->legend->setSelectable(QCPLegend::spItems);
    dbPlot->xAxis->setVisible(true);
    dbPlot->xAxis->setTickLabels(true);
    dbPlot->yAxis->setLabel("Magnitude (dB)");
    dbPlot->xAxis->setLabel("Frequency (MHz)");
    paPlot->xAxis->setLabel("Frequency (MHz)");
    paPlot->yAxis->setLabel("Phase (Radians)");

    QFont legendFont;
    legendFont.setPointSize(8);

    dbPlot->legend->setVisible(true);
    dbPlot->legend->setIconSize(10, 10);
    dbPlot->legend->setFont(legendFont);
    dbPlot->legend->setItemSpacing(0);
    dbPlot->legend->setPositionStyle(QCPLegend::psRight);

    plotLayout->addWidget(dbPlot);
    plotLayout->addWidget(paPlot);

    currentSelection = 0;

    this->setLayout(plotLayout);


    connect(dbPlot, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
}
Exemplo n.º 4
0
void DataExplorer::updateEnvironment() {
	ui->selectEnvironment->clearPlottables();
	int idx = 0;
	QVector<double> ticks;
	QVector<QString> labels;
	for (QCPAbstractPlottable *p : ui->selectMetric->selectedPlottables()) {
		int unit = p->property("UID").toInt();
        int eid = 0;
		for (const Environment* e : exp->runs.keys()) {
			StatisticalSet vals = e->aggregate(unit,exp);
			QCPStatisticalBox* b = new QCPStatisticalBox(ui->selectEnvironment->xAxis,ui->selectEnvironment->yAxis);
			b->setData(idx,vals.min(),vals.quantile(0.25),vals.median(),vals.quantile(0.75),vals.max());
            b->setProperty("UID",unit);
            b->setProperty("EID",eid++);
			ui->selectEnvironment->addPlottable(b);
			b->setSelected(true);
			labels.append(QString("%1 @ %2").arg(exp->data.at(unit)->descriptor->name(),e->label));
			ticks.append(idx++);
		}
	}
	ui->selectEnvironment->xAxis->setAutoTicks(false);
	ui->selectEnvironment->xAxis->setAutoTickLabels(false);
	ui->selectEnvironment->xAxis->setSubTickCount(0);
	ui->selectEnvironment->xAxis->setTickLength(0, 4);
	ui->selectEnvironment->xAxis->setTickLabelRotation(90);
	ui->selectEnvironment->xAxis->setTickVector(ticks);
	ui->selectEnvironment->xAxis->setTickVectorLabels(labels);
	ui->selectEnvironment->setInteractions(QCP::iMultiSelect | QCP::iSelectPlottables);
	ui->selectEnvironment->setSelectionTolerance(10);
	ui->selectEnvironment->rescaleAxes();
	ui->selectEnvironment->xAxis->scaleRange(1.1, ui->selectEnvironment->xAxis->range().center());
	connect(ui->selectEnvironment,SIGNAL(selectionChangedByUser()), this, SLOT(updateDetails()));
	if (ui->axisFromZero->isChecked())
		ui->selectEnvironment->yAxis->setRangeLower(0);
	ui->selectEnvironment->replot();
	updateDetails();
}
Exemplo n.º 5
0
void DataExplorer::on_dispUnit_currentIndexChanged(int)
{
	QVector<double> ticks;
	ui->selectMetric->clearPlottables();
	QBrush boxBrush(QColor(60, 60, 255, 100),Qt::Dense6Pattern);

	QVector<QString> labels;
	int i = -1;
	for (DataSeries* p : exp->data) {
		if (p == nullptr) continue;
		if (p->descriptor->unit() != ui->dispUnit->currentText()) continue;
		++i;
		StatisticalSet v = exp->aggregate(p->descriptor->uid(),exp);
		QCPStatisticalBox* b = new QCPStatisticalBox(ui->selectMetric->xAxis,ui->selectMetric->yAxis);
		b->setBrush(boxBrush);
		b->setProperty("UID",p->descriptor->uid());
		b->setData(i,v.min(),v.quantile(0.25),v.median(),v.quantile(0.75),v.max());
		ui->selectMetric->addPlottable(b);
		ticks.append(i);
		labels.append(p->descriptor->name());
	}
	ui->selectMetric->xAxis->setSubTickCount(0);
	ui->selectMetric->xAxis->setTickLength(0, 4);
	ui->selectMetric->xAxis->setTickLabelRotation(40);
	ui->selectMetric->xAxis->setAutoTicks(false);
	ui->selectMetric->xAxis->setAutoTickLabels(false);
	ui->selectMetric->xAxis->setTickVector(ticks);
	ui->selectMetric->xAxis->setTickVectorLabels(labels);
	ui->selectMetric->setInteractions(QCP::iMultiSelect | QCP::iSelectPlottables);

	ui->selectMetric->rescaleAxes();
	ui->selectMetric->xAxis->scaleRange(1.1, ui->selectMetric->xAxis->range().center());
	connect(ui->selectMetric,SIGNAL(selectionChangedByUser()), this, SLOT(updateEnvironment()));
	if (ui->axisFromZero->isChecked())
		ui->selectMetric->yAxis->setRangeLower(0);
	ui->selectMetric->replot();
}
Exemplo n.º 6
0
/**
 * Construct a line chart widget of a given parent, active measure, low and high range
 * @param parent chosen parent
 * @param meas  active measure
 * @param range low/high range of the data
 */
widgetBarChart::widgetBarChart(QWidget *parent, const Measure &meas, const std::pair<double, double> &range):QWidget(parent),ui(new Ui::widgetBarChart),_meas(new Measure(meas))
{
    ui->setupUi(this);
    _range =range;
    this->setStyleSheet(
                "QPushButton#pushButtonSaveBarData {"
                "background-color: rgb(125,125,175);"
                "border-style: outset;"
                "border-width: 2px;"
                "border-color: rgb(50,50,75);"
                "font: bold 22px;"
                "border-radius: 5px;"
                "min-width: 7em;}"

                "QPushButton#pushButtonSaveBarData:hover:pressed {"
                "background-color: rgb(100,100,145);"
                "border-style:inset;}"

                "QPushButton#pushButtonSaveBarData:hover {"
                "background-color: rgb(130,130,180);}"

                "QPushButton#pushButtonRefresh {"
                "background-color: rgb(125,125,175);"
                "border-style: outset;"
                "border-width: 2px;"
                "border-color: rgb(50,50,75);"
                "font: bold 22px;"
                "border-radius: 5px;"
                "min-width: 7em;}"

                "QPushButton#pushButtonRefresh:hover:pressed {"
                "background-color: rgb(100,100,145);"
                "border-style:inset;}"

                "QPushButton#pushButtonRefresh:hover {"
                "background-color: rgb(130,130,180); }"
                );
    ui->listBarChartMunicipality->setSelectionMode(QAbstractItemView::MultiSelection);
    ui->listBarChartYears->setSelectionMode(QAbstractItemView::MultiSelection);
    //List Stuff
    ui->listBarChartMunicipality->addItems(_meas->stringMuniList());
    ui->listBarChartYears->addItems(_meas->yearRange());

    //Add title to bar chart
    ui->widgetBarChart_2->plotLayout()->insertRow(0);
    QString title = meas.name() + " Over the Years";
    ui->widgetBarChart_2->plotLayout()->addElement(0, 0, new QCPPlotTitle(ui->widgetBarChart_2, title));
    ui->widgetBarChart_2->yAxis->setLabel(_meas->name());


    //*********************set interractions*************************
    srand(QDateTime::currentDateTime().toTime_t());
      ui->widgetBarChart_2->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
                                      QCP::iSelectLegend | QCP::iSelectPlottables);

      ui->widgetBarChart_2->axisRect()->setupFullAxesBox();
      ui->widgetBarChart_2->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items

      // connect slot that ties some axis selections together (especially opposite axes):
      connect(ui->widgetBarChart_2, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
      // connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
      connect(ui->widgetBarChart_2, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
      connect(ui->widgetBarChart_2, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));

      // make bottom and left axes transfer their ranges to top and right axes:
      connect(ui->widgetBarChart_2->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->widgetBarChart_2->xAxis2, SLOT(setRange(QCPRange)));
      connect(ui->widgetBarChart_2->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->widgetBarChart_2->yAxis2, SLOT(setRange(QCPRange)));

      // connect some interaction slots:
      connect(ui->widgetBarChart_2, SIGNAL(titleDoubleClick(QMouseEvent*,QCPPlotTitle*)), this, SLOT(titleDoubleClick(QMouseEvent*,QCPPlotTitle*)));
      connect(ui->widgetBarChart_2, SIGNAL(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)), this, SLOT(axisLabelDoubleClick(QCPAxis*,QCPAxis::SelectablePart)));
      connect(ui->widgetBarChart_2, SIGNAL(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)), this, SLOT(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*)));

      // setup policy and connect slot for context menu popup:
      ui->widgetBarChart_2->setContextMenuPolicy(Qt::CustomContextMenu);
      connect(ui->widgetBarChart_2, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));


    drawChart();

}
Exemplo n.º 7
0
graphWidget::graphWidget(QWidget *parent, trackHandler* _track) :
    QWidget(parent),
    ui(new Ui::graphWidget)
{
    phantomChanges = true;
    ui->setupUi(this);

    transitionHandler = ui->transitionEditor;

    selTrack = _track;
    selFunc = NULL;

    this->setMaximumHeight(300);
    this->setMinimumHeight(200);

    ui->povLine->hide();

    ui->selTree->setColumnWidth(0, 180);
    ui->selTree->setColumnWidth(1, 50);

    ui->plotter->yAxis->grid()->setVisible(false);
    ui->plotter->yAxis2->setVisible(true);

    yAxes[0] = ui->plotter->yAxis;
    yAxes[1] = ui->plotter->yAxis2;
    yAxes[2] = ui->plotter->axisRect()->addAxis(QCPAxis::atRight);
    yAxes[3] = ui->plotter->axisRect()->addAxis(QCPAxis::atLeft);

    yAxes[0]->setLabel(QString("Banking"));
    yAxes[1]->setLabel(QString("Forces"));
    yAxes[2]->setLabel(QString("Pitch"));
    yAxes[3]->setLabel(QString("Yaw"));

    ui->plotter->xAxis->grid()->setPen(QPen(QColor(220, 220, 220), 1, Qt::DotLine));
    ui->plotter->xAxis->grid()->setZeroLinePen(QPen(QPen(QColor(220, 220, 220), 1)));
    for(int i = 0; i < 4; ++i) {
        yAxes[i]->grid()->setPen(QPen(QColor(220, 220, 220), 1, Qt::DotLine));
        yAxes[i]->grid()->setZeroLinePen(QPen(QPen(QColor(220, 220, 220), 1)));
    }

    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(0)->child(0), banking, selTrack, yAxes[0], gloParent->mOptions->rollColor));
    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(0)->child(1), rollSpeed, selTrack, yAxes[0], gloParent->mOptions->rollColor));
    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(0)->child(2), rollAccel, selTrack, yAxes[0], gloParent->mOptions->rollColor));

    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(1)->child(0), nForce, selTrack, yAxes[1], gloParent->mOptions->normColor));
    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(1)->child(1), nForceChange, selTrack, yAxes[1], gloParent->mOptions->normColor));

    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(2)->child(0), lForce, selTrack, yAxes[1], gloParent->mOptions->latColor));
    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(2)->child(1), lForceChange, selTrack, yAxes[1], gloParent->mOptions->latColor));

    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(3)->child(0), pitchChange, selTrack, yAxes[2], gloParent->mOptions->pitchColor));
    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(3)->child(1), yawChange, selTrack, yAxes[3], gloParent->mOptions->yawColor));

    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(2)->child(0), secBoundaries, selTrack, ui->plotter->yAxis, NULL));
    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(2)->child(1), povPos, selTrack, NULL, NULL));

    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(0)->child(1), smoothedRollSpeed, selTrack, yAxes[0], gloParent->mOptions->rollColor));
    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(1)->child(0), smoothedNForce, selTrack, yAxes[1], gloParent->mOptions->normColor));
    pGraphList.append(new graphHandler(ui->selTree->topLevelItem(1)->child(2)->child(0), smoothedLForce, selTrack, yAxes[1], gloParent->mOptions->latColor));

    ui->plotter->setInteraction(QCP::iRangeDrag, true);
    ui->plotter->setInteraction(QCP::iRangeZoom, true);
    ui->plotter->setInteraction(QCP::iSelectPlottables, true);

    ui->plotter->axisRect()->setRangeDrag(Qt::Horizontal);
    ui->plotter->axisRect()->setRangeZoomAxes(ui->plotter->xAxis, NULL);

    connect(ui->plotter, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(MousePressedPlotter()));
    connect(ui->plotter, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(setPlotRanges()));
    connect(ui->plotter, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(MouseWheelPlotter()));

    ui->plotter->setNotAntialiasedElement((QCP::AntialiasedElement)(0xFFFF ^ 0x0020), true);
    ui->plotter->setPlottingHint(QCP::phForceRepaint, true);


    connect(ui->plotter, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
    ui->tabWidget->removeTab(1);

    if(selTrack) {
        pGraphList[secBoundaries]->treeItem->setCheckState(1, Qt::Checked);
        pGraphList[secBoundaries]->drawn = true;
        pGraphList[povPos]->treeItem->setCheckState(1, Qt::Unchecked);
    }

    ui->transitionEditor->mParent = this;
    phantomChanges = false;
}
Exemplo n.º 8
0
Graph::Graph(QMainWindow *parent) :
    QMainWindow(parent)
{
    customPlot = new QCustomPlot;
    customPlot->setEnabled(false);

    srand(QDateTime::currentDateTime().toTime_t());

    customPlot->setInteractions(QCustomPlot::iRangeDrag | QCustomPlot::iRangeZoom | QCustomPlot::iSelectAxes |
                                    QCustomPlot::iSelectLegend | QCustomPlot::iSelectPlottables | QCustomPlot::iSelectTitle);
    customPlot->setRangeDrag(Qt::Horizontal|Qt::Vertical);
    customPlot->setRangeZoom(Qt::Horizontal|Qt::Vertical);
    customPlot->xAxis->setRange(0, 1);
    customPlot->yAxis->setRange(0, 1);
    customPlot->yAxis->setRangeReversed(true);
    customPlot->setupFullAxesBox();
    customPlot->xAxis->setLabel("x Axis");
    customPlot->yAxis->setLabel("y Axis");
    customPlot->legend->setVisible(true);
    QFont legendFont = font();
    legendFont.setPointSize(10);
    customPlot->legend->setFont(legendFont);
    customPlot->legend->setSelectedFont(legendFont);
    customPlot->legend->setSelectable(QCPLegend::spItems); // legend box shall not be selectable, only legend items


    // connect slot that ties some axis selections together (especially opposite axes):
    connect(customPlot, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
    // connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
    connect(customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
    connect(customPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));

    // make bottom and left axes transfer their ranges to top and right axes:
    connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
    connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));

    // connect some interaction slots:
    connect(customPlot, SIGNAL(titleDoubleClick(QMouseEvent*)), this, SLOT(titleDoubleClick()));
    connect(customPlot, SIGNAL(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)), this, SLOT(axisLabelDoubleClick(QCPAxis*,QCPAxis::SelectablePart)));
    connect(customPlot, SIGNAL(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)), this, SLOT(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*)));

    // connect slot that shows a message in the status bar when a graph is clicked:
    connect(customPlot, SIGNAL(plottableClick(QCPAbstractPlottable*,QMouseEvent*)), this, SLOT(graphClicked(QCPAbstractPlottable*)));

    // setup policy and connect slot for context menu popup:
    customPlot->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(customPlot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));






    // Oppretter databasen med databasedriver QODBC
    db = QSqlDatabase::addDatabase("QODBC");

    // Setter maksverdiene for x og y aksene til -1 for å være sikker på at de blir overskrevet
    xMax = -1;
    yMax = -1;

    // Setter startverdi for fargevelger variabelen
    colorCounter = 0;
}
Exemplo n.º 9
0
LogsDialog::LogsDialog(QWidget *parent) :
  QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
  ui(new Ui::LogsDialog)
{
  csvlog.clear();

  ui->setupUi(this);
  setWindowIcon(CompanionIcon("logs.png"));

  plotLock=false;

  colors.append(Qt::green);
  colors.append(Qt::red);
  colors.append(Qt::yellow);
  colors.append(Qt::magenta);
  colors.append(Qt::cyan);
  colors.append(Qt::darkBlue);
  colors.append(Qt::darkGreen);
  colors.append(Qt::darkRed);
  colors.append(Qt::darkYellow);
  colors.append(Qt::darkMagenta);
  colors.append(Qt::darkCyan);
  colors.append(Qt::blue);
  pen.setWidthF(1.0);

  // create and prepare a plot title layout element
  QCPPlotTitle *title = new QCPPlotTitle(ui->customPlot);
  title->setText(tr("Telemetry logs"));

  // add it to the main plot layout
  ui->customPlot->plotLayout()->insertRow(0);
  ui->customPlot->plotLayout()->addElement(0, 0, title);
  ui->customPlot->setNoAntialiasingOnDrag(true);
  ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables);

  axisRect = ui->customPlot->axisRect();
  axisRect->axis(QCPAxis::atBottom)->setLabel(tr("Time (hh:mm:ss)"));
  axisRect->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime);
  axisRect->axis(QCPAxis::atBottom)->setDateTimeFormat("hh:mm:ss");
  QDateTime now = QDateTime::currentDateTime();
  axisRect->axis(QCPAxis::atBottom)->setRange(now.addSecs(-60*60*2).toTime_t(), now.toTime_t());
  axisRect->axis(QCPAxis::atLeft)->setTickLabels(false);
  axisRect->addAxis(QCPAxis::atLeft);
  axisRect->addAxis(QCPAxis::atRight);
  axisRect->axis(QCPAxis::atLeft, 1)->setVisible(false);
  axisRect->axis(QCPAxis::atRight, 1)->setVisible(false);

  QFont legendFont = font();
  legendFont.setPointSize(10);
  ui->customPlot->legend->setFont(legendFont);
  ui->customPlot->legend->setSelectedFont(legendFont);
  axisRect->insetLayout()->setInsetAlignment(0, Qt::AlignTop | Qt::AlignLeft);

  rightLegend = new QCPLegend;
  axisRect->insetLayout()->addElement(rightLegend, Qt::AlignTop | Qt::AlignRight);
  rightLegend->setLayer("legend");
  rightLegend->setFont(legendFont);
  rightLegend->setSelectedFont(legendFont);
  rightLegend->setVisible(false);

  ui->customPlot->setAutoAddPlottableToLegend(false);

  QString path = g.gePath();
  if (path.isEmpty() || !QFile(path).exists()) {
    ui->mapsButton->hide();
  }

  // connect slot that ties some axis selections together (especially opposite axes):
  connect(ui->customPlot, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
  // connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
  connect(ui->customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
  connect(ui->customPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));

  // make left axes transfer its range to right axes:
  connect(axisRect->axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), this, SLOT(yAxisChangeRanges(QCPRange)));

  // connect some interaction slots:
  connect(ui->customPlot, SIGNAL(titleDoubleClick(QMouseEvent*, QCPPlotTitle*)), this, SLOT(titleDoubleClick(QMouseEvent*, QCPPlotTitle*)));
  connect(ui->customPlot, SIGNAL(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)), this, SLOT(axisLabelDoubleClick(QCPAxis*,QCPAxis::SelectablePart)));
  connect(ui->customPlot, SIGNAL(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)), this, SLOT(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*)));
  connect(ui->FieldsTW, SIGNAL(itemSelectionChanged()), this, SLOT(plotLogs()));
  connect(ui->logTable, SIGNAL(itemSelectionChanged()), this, SLOT(plotLogs()));
  connect(ui->Reset_PB, SIGNAL(clicked()), this, SLOT(plotLogs()));
}