//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuSummaryQwtPlot::setDefaults() { QPalette newPalette(palette()); newPalette.setColor(QPalette::Background, Qt::white); setPalette(newPalette); setAutoFillBackground(true); setCanvasBackground(Qt::white); QFrame* canvasFrame = dynamic_cast<QFrame*>(canvas()); if (canvasFrame) { canvasFrame->setFrameShape(QFrame::NoFrame); } canvas()->setMouseTracking(true); canvas()->installEventFilter(this); QPen gridPen(Qt::SolidLine); gridPen.setColor(Qt::lightGray); m_grid->setPen(gridPen); enableAxis(QwtPlot::xBottom, true); enableAxis(QwtPlot::yLeft, true); enableAxis(QwtPlot::xTop, false); enableAxis(QwtPlot::yRight, false); plotLayout()->setAlignCanvasToScales(true); useDateBasedTimeAxis(); QFont xAxisFont = axisFont(QwtPlot::xBottom); xAxisFont.setPixelSize(11); setAxisFont(QwtPlot::xBottom, xAxisFont); setAxisMaxMinor(QwtPlot::xBottom, 2); QFont yAxisFont = axisFont(QwtPlot::yLeft); yAxisFont.setPixelSize(11); setAxisFont(QwtPlot::yLeft, yAxisFont); setAxisMaxMinor(QwtPlot::yLeft, 3); QwtText axisTitleY = axisTitle(QwtPlot::yLeft); QFont yAxisTitleFont = axisTitleY.font(); yAxisTitleFont.setPixelSize(11); yAxisTitleFont.setBold(false); axisTitleY.setFont(yAxisTitleFont); axisTitleY.setRenderFlags(Qt::AlignRight); setAxisTitle(QwtPlot::yLeft, axisTitleY); QwtLegend* legend = new QwtLegend(this); // The legend will be deleted in the destructor of the plot or when // another legend is inserted. this->insertLegend(legend, BottomLegend); }
/** * Set the scale of the horizontal axis * @param from :: Minimum value * @param to :: Maximum value */ void OneCurvePlot::setXScale(double from, double to) { QFontMetrics fm(axisFont(QwtPlot::xBottom)); int n = from != 0.0 ? abs(static_cast<int>(floor(log10(fabs(from))))) : 0; int n1 = to != 0.0 ? abs(static_cast<int>(floor(log10(fabs(to))))) : 0; if (n1 > n) n = n1; n += 4; // approxiamte width of a tick label in pixels int labelWidth = n * fm.width("0"); // calculate number of major ticks int nMajorTicks = this->width() / labelWidth; if ( nMajorTicks > 6 ) nMajorTicks = 6; // try creating a scale const QwtScaleDiv div = axisScaleEngine(QwtPlot::xBottom)->divideScale(from,to,nMajorTicks,nMajorTicks); // Major ticks are placed at round numbers so the first or last tick could be missing making // scale look ugly. Trying to fix it if possible bool rescaled = false; // get actual tick positions const QwtValueList& ticks = div.ticks(QwtScaleDiv::MajorTick); if (!ticks.empty() && ticks.size() < nMajorTicks) { // how much first tick is shifted from the lower bound double firstShift = ticks.front() - div.lBound(); // how much last tick is shifted from the upper bound double lastShift = div.hBound() - ticks.back(); // range of the scale double range = fabs(div.hBound() - div.lBound()); // we say that 1st tick is missing if first tick is father away from its end of the scale // than the last tick is from its end bool isFirstMissing = fabs(firstShift) > fabs(lastShift) ; // if first tick is missing if (isFirstMissing) { // distance between nearest major ticks double tickSize = 0; if (ticks.size() == 1) { // guess the tick size in case of only one visible double tickLog = log10(firstShift); tickLog = tickLog > 0 ? ceil(tickLog) : floor(tickLog); tickSize = pow(10.,tickLog); } else if (ticks.size() > 1) { // take the difference between the two first ticks tickSize = ticks[1] - ticks[0]; } // claculate how much lower bound must be moved to make the missing tick visible double shift = (ticks.front() - tickSize) - from; // if the shift is not very big rescale the axis if (fabs(shift/range) < 0.1) { from += shift; const QwtScaleDiv updatedDiv = axisScaleEngine(QwtPlot::xBottom)->divideScale(from,to,nMajorTicks,nMajorTicks); setAxisScaleDiv(xBottom,updatedDiv); rescaled = true; } } else // last tick is missing { // distance between nearest major ticks double tickSize = 0; if (ticks.size() == 1) { // guess the tick size in case of only one visible double tickLog = log10(lastShift); tickLog = tickLog > 0 ? ceil(tickLog) : floor(tickLog); tickSize = pow(10.,tickLog); } else if (ticks.size() > 1) { // take the difference between the two first ticks tickSize = ticks[1] - ticks[0]; } // claculate how much upper bound must be moved to make the missing tick visible double shift = (ticks.back() + tickSize) - to; // if the shift is not very big rescale the axis if (fabs(shift/range) < 0.1) { to += shift; const QwtScaleDiv updatedDiv = axisScaleEngine(QwtPlot::xBottom)->divideScale(from,to,nMajorTicks,nMajorTicks); setAxisScaleDiv(xBottom,updatedDiv); rescaled = true; } } } if (!rescaled) { setAxisScaleDiv(xBottom,div); } m_zoomer->setZoomBase(); }
void SingleCellViewGraphPanelPlotWidget::drawCoordinates(QPainter *pPainter, const QPointF &pCoordinates, const QColor &pBackgroundColor, const QColor &pForegroundColor, const Location &pLocation, const bool &pCanMoveLocation) { // Retrieve the size of coordinates as they will appear on the screen, // which means using the same font as the one used for the axes pPainter->setFont(axisFont(QwtPlot::xBottom)); QString coords = QString("(%1, %2)").arg(QString::number(pCoordinates.x()), QString::number(pCoordinates.y())); QRect desktopGeometry = qApp->desktop()->availableGeometry(); QRectF coordsRect = pPainter->boundingRect(QRectF(0.0, 0.0, desktopGeometry.width(), desktopGeometry.height()), coords); // Determine where the coordinates and its background should be drawn QPoint coordinates = QPoint(canvasMap(QwtPlot::xBottom).transform(pCoordinates.x()), canvasMap(QwtPlot::yLeft).transform(pCoordinates.y())); switch (pLocation) { case TopLeft: coordsRect.moveTo(coordinates.x()-coordsRect.right()-1, coordinates.y()-coordsRect.bottom()-1); break; case TopRight: coordsRect.moveTo(coordinates.x()+2, coordinates.y()-coordsRect.bottom()-1); break; case BottomLeft: coordsRect.moveTo(coordinates.x()-coordsRect.right()-1, coordinates.y()+2); break; case BottomRight: coordsRect.moveTo(coordinates.x()+2, coordinates.y()+2); break; } if (pCanMoveLocation) { if (coordsRect.top() < 0) coordsRect.moveTop(coordinates.y()+2); if (coordsRect.left() < 0) coordsRect.moveLeft(coordinates.x()+2); if (coordsRect.bottom() > plotLayout()->canvasRect().height()) coordsRect.moveTop(coordinates.y()-coordsRect.height()-1); if (coordsRect.right() > plotLayout()->canvasRect().width()) coordsRect.moveLeft(coordinates.x()-coordsRect.width()-1); } // Draw a filled rectangle to act as the background of the coordinates // we are to show pPainter->fillRect(coordsRect, pBackgroundColor); // Draw the text for the coordinates, using a white pen QPen pen = pPainter->pen(); pen.setColor(pForegroundColor); pPainter->setPen(pen); pPainter->drawText(coordsRect, coords); }
bool Plot3DDialog::updatePlot() { int axis=-1; if (generalDialog->currentWidget()==(QWidget*)bars) { emit updateBars(boxBarsRad->text().toDouble()); } if (generalDialog->currentWidget()==(QWidget*)points) { if (boxPointStyle->currentItem() == 0) emit updatePoints(boxSize->text().toDouble(), boxSmooth->isChecked()); else if (boxPointStyle->currentItem() == 1) emit updateCross(boxCrossRad->text().toDouble(), boxCrossLinewidth->text().toDouble(), boxCrossSmooth->isChecked(), boxBoxed->isChecked()); else if (boxPointStyle->currentItem() == 2) emit updateCones(boxConesRad->text().toDouble(), boxQuality->value()); } if (generalDialog->currentWidget()==(QWidget*)title) { emit updateTitle(boxTitle->text(),titleColor,titleFont); } if (generalDialog->currentWidget()==(QWidget*)colors) { emit updateTransparency(boxTransparency->value()*0.01); emit updateDataColors(fromColor,toColor); emit updateColors(meshColor,axesColor,numColor,labelColor,bgColor,gridColor); } if (generalDialog->currentWidget()==(QWidget*)general) { emit showColorLegend(boxLegend->isChecked()); emit updateMeshLineWidth(boxMeshLineWidth->value()); emit adjustLabels(boxDistance->value()); emit updateResolution (boxResolution->value()); emit showColorLegend(boxLegend->isChecked()); emit setNumbersFont(numbersFont); emit updateZoom(boxZoom->value()*0.01); emit updateScaling(boxXScale->value()*0.01,boxYScale->value()*0.01, boxZScale->value()*0.01); } if (generalDialog->currentWidget()==(QWidget*)scale) { axis=axesList->currentRow(); QString from=boxFrom->text().toLower(); QString to=boxTo->text().toLower(); double start,end; bool error=false; try { MyParser parser; parser.SetExpr(from.toAscii().constData()); start=parser.Eval(); } catch(mu::ParserError &e) { QMessageBox::critical(0,tr("Start limit error"), QString::fromStdString(e.GetMsg())); boxFrom->setFocus(); error=true; return false; } try { MyParser parser; parser.SetExpr(to.toAscii().constData()); end=parser.Eval(); } catch(mu::ParserError &e) { QMessageBox::critical(0,tr("End limit error"), QString::fromStdString(e.GetMsg())); boxTo->setFocus(); error=true; return false; } if (start>=end) { QMessageBox::critical(0,tr("Input error"), tr("Please enter scale limits that satisfy: from < to!")); boxTo->setFocus(); return false; } if (! error) emit updateScale(axis,scaleOptions(axis, start, end, boxMajors->text(), boxMinors->text())); } if (generalDialog->currentWidget()==(QWidget*)axes) { axis=axesList2->currentRow(); labels[axis] = boxLabel->text(); emit updateLabel(axis, boxLabel->text(),axisFont(axis)); emit updateTickLength(axis,boxMajorLength->text().toDouble(), boxMinorLength->text().toDouble()); } return true; }
QFont SaxsviewImage::tickLabelFont() const { return axisFont(QwtPlot::xBottom); }
void COScopeCtrl::RecreateGrid() { // There is a lot of drawing going on here - particularly in terms of // drawing the grid. Don't panic, this is all being drawn (only once) // to a bitmap. The result is then BitBlt'd to the control whenever needed. bRecreateGrid = false; if (m_rectClient.GetWidth() == 0 || m_rectClient.GetHeight() == 0) { return; } wxMemoryDC dcGrid(m_bmapGrid); wxPen solidPen = *(wxThePenList->FindOrCreatePen(m_gridColour, 1, wxSOLID)); wxString strTemp; // fill the grid background dcGrid.SetBrush(brushBack); dcGrid.SetPen(*wxTRANSPARENT_PEN); dcGrid.DrawRectangle(m_rectClient); // adjust the plot rectangle dimensions // assume 6 pixels per character (this may need to be adjusted) m_rectPlot.x = m_rectClient.GetLeft() + 6*7+4; // draw the plot rectangle dcGrid.SetPen(solidPen); dcGrid.DrawRectangle(m_rectPlot.x - 1, m_rectPlot.y - 1, m_rectPlot.GetWidth() + 2, m_rectPlot.GetHeight() + 2); dcGrid.SetPen(wxNullPen); // create some fonts (horizontal and vertical) wxFont axisFont(10, wxSWISS, wxNORMAL, wxNORMAL, false); dcGrid.SetFont(axisFont); // y max dcGrid.SetTextForeground(m_gridColour); if( strYMax.IsEmpty() ) { strTemp = wxString::Format(wxT("%.*f"), nYDecimals, pdsTrends[ 0 ].fUpperLimit); } else { strTemp = strYMax; } wxCoord sizX,sizY; dcGrid.GetTextExtent(strTemp,&sizX,&sizY); dcGrid.DrawText(strTemp,m_rectPlot.GetLeft()-4-sizX,m_rectPlot.GetTop()-7); // y min if( strYMin.IsEmpty() ) { strTemp = wxString::Format(wxT("%.*f"), nYDecimals, pdsTrends[ 0 ].fLowerLimit) ; } else { strTemp = strYMin; } dcGrid.GetTextExtent(strTemp,&sizX,&sizY); dcGrid.DrawText(strTemp,m_rectPlot.GetLeft()-4-sizX, m_rectPlot.GetBottom()); // x units strTemp = CastSecondsToHM((m_rectPlot.GetWidth()/nShiftPixels) * (int)floor(sLastPeriod+0.5)); // floor(x + 0.5) is a way of doing round(x) that works with gcc < 3 ... if (bStopped) { strXUnits = CFormat( _("Disabled [%s]") ) % strTemp; } else { strXUnits = strTemp; } dcGrid.GetTextExtent(strXUnits,&sizX,&sizY); dcGrid.DrawText(strXUnits,(m_rectPlot.GetLeft() + m_rectPlot.GetRight())/2-sizX/2,m_rectPlot.GetBottom()+4); // y units if (!strYUnits.IsEmpty()) { dcGrid.GetTextExtent(strYUnits,&sizX,&sizY); dcGrid.DrawText(strYUnits, m_rectPlot.GetLeft()-4-sizX, (m_rectPlot.GetTop()+m_rectPlot.GetBottom())/2-sizY/2); } // no more drawing to this bitmap is needed until the setting are changed if (bRecreateGraph) { RecreateGraph(false); } // finally, force the plot area to redraw Refresh(false); }
bool Plot3DDialog::updatePlot() { if (!d_plot) return false; ApplicationWindow *app = (ApplicationWindow *)this->parent(); if (!app) return false; if (generalDialog->currentPage()==(QWidget*)bars){ d_plot->setBarRadius(boxBarsRad->text().toDouble()); d_plot->setBarStyle(); } else if (generalDialog->currentPage() == (QWidget*)points){ if (boxPointStyle->currentIndex() == 0) { d_plot->setDotOptions(boxSize->text().toDouble(), boxSmooth->isChecked()); d_plot->setDotStyle(); } else if (boxPointStyle->currentIndex() == 1){ d_plot->setCrossOptions(boxCrossRad->text().toDouble(), boxCrossLinewidth->text().toDouble(), boxCrossSmooth->isChecked(), boxBoxed->isChecked()); d_plot->setCrossStyle(); } else if (boxPointStyle->currentIndex() == 2) { d_plot->setConeOptions(boxConesRad->text().toDouble(), boxQuality->value()); d_plot->setConeStyle(); } app->custom3DActions(d_plot); } else if (generalDialog->currentPage()==(QWidget*)title){ d_plot->setTitle(boxTitle->text().remove("\n"), btnTitleColor->color(), titleFont); } else if (generalDialog->currentPage()==(QWidget*)colors){ d_plot->changeTransparency(boxTransparency->value()*0.01); d_plot->setDataColors(btnFromColor->color(), btnToColor->color()); d_plot->setMeshColor(btnMesh->color()); d_plot->setAxesColor(btnAxes->color()); d_plot->setNumbersColor(btnNumbers->color()); d_plot->setLabelsColor(btnLabels->color()); d_plot->setBackgroundColor(btnBackground->color()); d_plot->setGridColor(btnGrid->color()); } else if (generalDialog->currentPage()==(QWidget*)general){ d_plot->showColorLegend(boxLegend->isChecked()); d_plot->setResolution(boxResolution->value()); d_plot->setMeshLineWidth(boxMeshLineWidth->value()); d_plot->setLabelsDistance(boxDistance->value()); d_plot->setNumbersFont(numbersFont); d_plot->setZoom(boxZoom->value()*0.01); d_plot->setScale(boxXScale->value()*0.01, boxYScale->value()*0.01, boxZScale->value()*0.01); } else if (generalDialog->currentPage()==(QWidget*)scale){ int axis = axesList->currentRow(); QString from=boxFrom->text().lower(); QString to=boxTo->text().lower(); double start, end; try { MyParser parser; parser.SetExpr(from.ascii()); start = parser.Eval(); } catch(mu::ParserError &e){ QMessageBox::critical(0,tr("QtiPlot - Start limit error"), QString::fromStdString(e.GetMsg())); boxFrom->setFocus(); return false; } try { MyParser parser; parser.SetExpr(to.ascii()); end = parser.Eval(); } catch(mu::ParserError &e){ QMessageBox::critical(0,tr("QtiPlot - End limit error"), QString::fromStdString(e.GetMsg())); boxTo->setFocus(); return false; } d_plot->updateScale(axis, scaleOptions(axis, start, end, boxMajors->text(), boxMinors->text())); } else if (generalDialog->currentPage()==(QWidget*)axes){ int axis = axesList2->currentRow(); labels[axis] = boxLabel->text(); switch(axis) { case 0: d_plot->setXAxisLabel(boxLabel->text().remove("\n")); d_plot->setXAxisLabelFont(axisFont(axis)); d_plot->setXAxisTickLength(boxMajorLength->text().toDouble(), boxMinorLength->text().toDouble()); break; case 1: d_plot->setYAxisLabel(boxLabel->text().remove("\n")); d_plot->setYAxisLabelFont(axisFont(axis)); d_plot->setYAxisTickLength(boxMajorLength->text().toDouble(), boxMinorLength->text().toDouble()); break; case 2: d_plot->setZAxisLabel(boxLabel->text().remove("\n")); d_plot->setZAxisLabelFont(axisFont(axis)); d_plot->setZAxisTickLength(boxMajorLength->text().toDouble(), boxMinorLength->text().toDouble()); break; } } d_plot->update(); app->modifiedProject(d_plot); return true; }
bool Plot3DDialog::updatePlot() { if (!d_plot) return false; ApplicationWindow *app = (ApplicationWindow *)this->parent(); if (!app) return false; if (generalDialog->currentPage() == bars) { d_plot->setBarRadius(boxBarsRad->text().toDouble()); d_plot->setBarLines(boxBarLines->isChecked()); d_plot->setFilledBars(boxFilledBars->isChecked()); d_plot->setBarStyle(); } else if (generalDialog->currentPage() == points) { if (boxPointStyle->currentIndex() == 0) { d_plot->setDotOptions(boxSize->text().toDouble(), boxSmooth->isChecked()); d_plot->setDotStyle(); } else if (boxPointStyle->currentIndex() == 1) { d_plot->setCrossOptions(boxCrossRad->text().toDouble(), boxCrossLinewidth->text().toDouble(), boxCrossSmooth->isChecked(), boxBoxed->isChecked()); d_plot->setCrossStyle(); } else if (boxPointStyle->currentIndex() == 2) { d_plot->setConeOptions(boxConesRad->text().toDouble(), boxQuality->value()); d_plot->setConeStyle(); } app->custom3DActions(d_plot); } else if (generalDialog->currentPage() == title) { d_plot->setTitle(boxTitle->text().remove("\n"), btnTitleColor->color(), titleFont); } else if (generalDialog->currentPage() == colors) { d_plot->changeTransparency(boxTransparency->value()*0.01); if (linearColorMapGroupBox->isChecked()) d_plot->setDataColorMap(d_color_map_editor->colorMap()); else if (colorMapFileGroupBox->isChecked() && !d_color_map_file.isEmpty()) { d_plot->setDataColorMap(d_color_map_file); setColorMapPreview(d_color_map_file); } d_plot->setMeshColor(btnMesh->color()); d_plot->setAxesColor(btnAxes->color()); d_plot->setNumbersColor(btnNumbers->color()); d_plot->setLabelsColor(btnLabels->color()); d_plot->setBackgroundColor(btnBackground->color()); } else if (generalDialog->currentPage() == gridPage) { Qwt3D::GridLine majorGrid(boxMajorGrids->isChecked(), Qt2GL(btnGrid->color()), (Qwt3D::LINESTYLE)boxMajorGridStyle->currentIndex(), boxMajorGridWidth->value()); Qwt3D::GridLine minorGrid(boxMinorGrids->isChecked(), Qt2GL(btnGridMinor->color()), (Qwt3D::LINESTYLE)boxMinorGridStyle->currentIndex(), boxMinorGridWidth->value()); for (int i = 0; i < 12; i++) { d_plot->coordinateSystem()->setMajorGridLines((Qwt3D::AXIS)i, majorGrid); d_plot->coordinateSystem()->setMinorGridLines((Qwt3D::AXIS)i, minorGrid); } } else if (generalDialog->currentPage() == general) { d_plot->showColorLegend(boxLegend->isChecked()); d_plot->setResolution(boxResolution->value()); d_plot->setMeshLineWidth(boxMeshLineWidth->value()); d_plot->setLabelsDistance(boxDistance->value()); d_plot->setNumbersFont(numbersFont); d_plot->setZoom(zoom*boxZoom->value()*0.01); d_plot->setScale(xScale*boxXScale->value()*0.01, yScale*boxYScale->value()*0.01, zScale*boxZScale->value()*0.01); d_plot->setRotation(boxXRotation->value(), boxYRotation->value(), boxZRotation->value()); } else if (generalDialog->currentPage() == (QWidget*)scale) { double start = qMin(boxFrom->value(), boxTo->value()); double end = qMax(boxFrom->value(), boxTo->value()); d_plot->setScale(axesList->currentRow(), start, end, boxMajors->value() - 1, boxMinors->value() + 1, (Qwt3D::SCALETYPE)boxType->currentIndex()); d_plot->setAxisNumericFormat(axesList->currentRow(), boxTickLabelsFormat->currentIndex(), boxPrecision->value()); viewScaleLimits(axesList->currentRow()); } else if (generalDialog->currentPage() == axes) { int axis = axesList2->currentRow(); labels[axis] = boxLabel->text(); switch(axis) { case 0: d_plot->setXAxisLabel(boxLabel->text().remove("\n")); d_plot->setXAxisLabelFont(axisFont(axis)); d_plot->setXAxisTickLength(boxMajorLength->value(), boxMinorLength->value()); break; case 1: d_plot->setYAxisLabel(boxLabel->text().remove("\n")); d_plot->setYAxisLabelFont(axisFont(axis)); d_plot->setYAxisTickLength(boxMajorLength->value(), boxMinorLength->value()); break; case 2: d_plot->setZAxisLabel(boxLabel->text().remove("\n")); d_plot->setZAxisLabelFont(axisFont(axis)); d_plot->setZAxisTickLength(boxMajorLength->value(), boxMinorLength->value()); break; } } else if (generalDialog->currentPage() == printPage) { d_plot->printCropmarks(boxPrintCropmarks->isChecked()); d_plot->setScaleOnPrint(boxScaleOnPrint->isChecked()); } d_plot->update(); app->modifiedProject(d_plot); return true; }