예제 #1
0
void GenericHistogramView::init()
{
  this->setMouseTracking(true); //Switch on mouse tracking (no need to press button)

  _qwtPlot->setTitle("Histogram");
  
  _qwtPlot->setCanvasBackground(QColor(Qt::gray));
  _qwtPlot->plotLayout()->setAlignCanvasToScales(true);

  _qwtPlot->setAxisTitle(QwtPlot::yLeft, "Number of specimen");
  _qwtPlot->setAxisTitle(QwtPlot::xBottom, "Pixel value");

	QwtLegend* legend = new QwtLegend();
  legend->setItemMode(QwtLegend::CheckableItem);
  _qwtPlot->insertLegend(legend, QwtPlot::RightLegend);

  populate();
  
  _qwtPlot->canvas()->setMouseTracking(true);
  
  if(_horizontal)
  _principalPicker = new HistogramPicker(QwtPlotPicker::HLineRubberBand, QwtPicker::AlwaysOn, _qwtPlot->canvas());
  else
  _principalPicker = new HistogramPicker(QwtPlotPicker::VLineRubberBand, QwtPicker::AlwaysOn, _qwtPlot->canvas());
  _principalPicker->setStateMachine(new QwtPickerDragPointMachine());
  _principalPicker->setTrackerPen(QColor(Qt::white));
  _principalPicker->setRubberBandPen(QColor(Qt::yellow));
  
  _leftPicker = new HistogramPicker(_qwtPlot->canvas());
  _leftPicker->setStateMachine(new QwtPickerDragPointMachine());
  
  _rightPicker = new HistogramPicker(_qwtPlot->canvas());
  _rightPicker->setStateMachine(new QwtPickerDragPointMachine());
  _rightPicker->setRubberBand(QwtPlotPicker::VLineRubberBand);
  _rightPicker->setRubberBandPen(QColor(Qt::yellow));
	_rightPicker->setMousePattern(QwtPicker::MouseSelect1, Qt::RightButton);

  connect(_qwtPlot, SIGNAL(legendChecked(QwtPlotItem*, bool)), this, SLOT(showItem(QwtPlotItem*, bool)));
  connect(_rightPicker, SIGNAL(selected(const QPointF&)), this, SLOT(rightClick(const QPointF&)));
  connect(_leftPicker, SIGNAL(selected(const QPointF&)), this, SLOT(leftClick(const QPointF&)));
  connect(_principalPicker, SIGNAL(moved(const QPointF&)), this, SLOT(move(const QPointF&)));

  _qwtPlot->replot(); // creating the legend items

  QwtPlotItemList items = _qwtPlot->itemList(QwtPlotItem::Rtti_PlotHistogram);
  for(int i = 0; i < items.size(); i++)
  {
      QwtLegendItem* legendItem = qobject_cast<QwtLegendItem*>(legend->find(items[i]));
      if(legendItem)
    legendItem->setChecked(true);

  items[i]->setVisible(true);
  }

  _qwtPlot->setAutoReplot(true);
}
예제 #2
0
void MainWindow::showCurve(QwtPlotItem *item, bool on)
{
    item->setVisible(on);

    QwtLegendItem *legendItem = qobject_cast<QwtLegendItem*>(ui->plot->legend()->find(item));

    if (legendItem) {
        legendItem->setChecked(on);
    }
}
예제 #3
0
void MainWindow::sampleFormatChanged()
{
    for (int i = 0; i < curves.size(); i++) {
        curves[i].curve->detach();
        delete curves[i].curve;
        curves[i].data->clear();
        delete curves[i].data;
    }
    curves.clear();
    timeAxis.clear();

    QList<sampleValue> sampleList = kwp.getSample();
    int numSamples = settingsDialog->rate * settingsDialog->historySecs + 1;

    timeAxis.clear();
    for (int i = 0; i < numSamples; i++) {
        timeAxis.prepend(-i / static_cast<double>(settingsDialog->rate));
    }

    int numColors = sizeof(colorList) / sizeof(QString);

    for (int i = 0; i < sampleList.length(); i++) {
        QwtPlotCurve* curve = new QwtPlotCurve;
        QVector<double>* data = new QVector<double>();
        data->reserve(numSamples+1);
        data->fill(0, numSamples);

        QColor curveColor;
        curveColor.setNamedColor(colorList[i % numColors]);

        int blockNum = sampleList.at(i).refs.at(0).blockNum;
        int pos = sampleList.at(i).refs.at(0).pos;
        blockLabels_t label = kwp.getBlockLabel(blockNum);
        QString desc = label.desc[pos] + " " + label.subDesc[pos];

        curve->setRenderHint(QwtPlotItem::RenderAntialiased);
        curve->setPen(curveColor);
        curve->setTitle(desc);

        curve->setRawSamples(timeAxis.constData(), data->constData(), numSamples);
        curve->attach(ui->plot);

        // set legend checked
        QwtLegendItem *legendItem = qobject_cast<QwtLegendItem*>(ui->plot->legend()->find(curve));
        if (legendItem) {
            legendItem->setChecked(true);
        }

        curveAndData tmp;
        tmp.curve = curve;
        tmp.data = data;
        curves.append(tmp);
    }
}
//---------------------------------------------------------------------------
void JrkPlotDialog::showCurve(QwtPlotItem *item, bool on)
{
    //qDebug("showCurve");

    item->setVisible(on);

    QwtLegendItem *legendItem =
        qobject_cast<QwtLegendItem *>(ui->jrkPlot->legend()->find(item));

    if(legendItem)
        legendItem->setChecked(on);

    //ui->jrkPlot->replot();
}
예제 #5
0
LevelOneMuChart::LevelOneMuChart(QWidget *parent)
    : QwtPlot(parent)
{
    setAutoReplot(false);

    /* Panning with the left mouse button */
    (void)new QwtPlotPanner(canvas());

    /* Zoom in/out with the wheel */
    (void)new QwtPlotMagnifier(canvas());

    /* Picker  */
    plotPicker = new QwtPlotPicker(QwtPlot::xBottom,
                                   QwtPlot::yLeft,
                                   QwtPlotPicker::CrossRubberBand,
                                   QwtPicker::AlwaysOn,
                                   canvas());
    plotPicker->setStateMachine(new QwtPickerDragPointMachine());
    plotPicker->setRubberBandPen(QColor(Qt::blue));
    plotPicker->setRubberBand(QwtPicker::CrossRubberBand);
    plotPicker->setTrackerPen(QColor(Qt::black));

    setAutoFillBackground(true);
    setPalette(QPalette(QColor(199, 237, 255))); // Light Blue

    updateWidgetGradient();

    setTitle(tr("Chart of available deviations"));

    /* Legend */
    legend = new QwtLegend();
    legend->setItemMode(QwtLegend::CheckableItem);
    insertLegend(legend, QwtPlot::RightLegend);

    /* Canvas Settings */
    canvas()->setLineWidth(1);
    canvas()->setFrameStyle(QFrame::Box | QFrame::Plain);

    QPalette canvasPalette(Qt::white);
    canvasPalette.setColor(QPalette::Foreground, QColor(133, 190, 232));
    canvas()->setPalette(canvasPalette);

    plotAssay();

    /* Legend */
    connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
            SLOT(showItem(QwtPlotItem *, bool)));

    QwtPlotItemList items = itemList(QwtPlotItem::Rtti_PlotCurve);
    for (int i = 0; i < items.size(); i++)
    {
        if (i < 3)
        {
            QwtLegendItem *legendItem =
                    qobject_cast<QwtLegendItem *>(legend->find(items[i]));
            if (legendItem)
            {
                legendItem->setChecked(true);
            }
            items[i]->setVisible(true);
        }
        else
        {
            items[i]->setVisible(false);
        }
    }
    setAutoReplot(true);
}