MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), config(), configUI(&config), experiment(&config, this), qwtPlotCurveHallU("Hall U"), qwtPlotCurveResistivity("Resistivity"), ui(new Ui::MainWindow) { experiment.setObjectName("experiment"); ui->setupUi(this); QObject::connect(&configUI, SIGNAL(accepted()), this, SLOT(show())); QObject::connect(&experiment, SIGNAL(coilBMeasured(double)), ui->coilBDoubleSpinBox, SLOT(setValue(double))); QObject::connect(&experiment, SIGNAL(coilIMeasured(double)), ui->coilCurrMeasDoubleSpinBox, SLOT(setValue(double))); QObject::connect(&experiment, SIGNAL(coilUMeasured(double)), ui->coilVoltMeasDoubleSpinBox, SLOT(setValue(double))); ui->qwtPlot->enableAxis(QwtPlot::yRight, true); QString titleTpl("<html><body><span style=\"font-family:'Sans Serif'; font-size:14pt; font-weight:600; font-style:bold;\"><span style=\"%1\">%2</span> %3</span></body></html>"); QwtText titleHall(titleTpl.arg("color: red;").arg("×").arg("hall U [V]")); QwtText titleR(titleTpl.arg("color: lime;").arg("*").arg("Resistivity [Ω]")); ui->qwtPlot->setAxisTitle(QwtPlot::yLeft, titleHall); ui->qwtPlot->setAxisTitle(QwtPlot::yRight, titleR); ui->qwtPlot->setAxisTitle(QwtPlot::xBottom, "B [T]"); qwtPlotCurveHallU.attach(ui->qwtPlot); qwtPlotCurveResistivity.attach(ui->qwtPlot); qwtPlotCurveHallU.setStyle(QwtPlotCurve::NoCurve); qwtPlotCurveResistivity.setStyle(QwtPlotCurve::NoCurve); QwtSymbol *qwtPlotHallUSymbol = new QwtSymbol(QwtSymbol::XCross); QwtSymbol *qwtPlotResistivitySymbol = new QwtSymbol(QwtSymbol::Star1); qwtPlotHallUSymbol->setColor(QColor(255, 0, 0)); qwtPlotResistivitySymbol->setColor(QColor(0, 255, 0)); qwtPlotHallUSymbol->setSize(QSize(12, 12)); qwtPlotResistivitySymbol->setSize(QSize(12, 12)); QPen hallSymbolPen(qwtPlotHallUSymbol->pen()); QPen resistivitySymbolPen(qwtPlotResistivitySymbol->pen()); hallSymbolPen.setWidth(2); resistivitySymbolPen.setWidth(2); qwtPlotHallUSymbol->setPen(hallSymbolPen); qwtPlotResistivitySymbol->setPen(resistivitySymbolPen); qwtPlotCurveResistivity.setYAxis(QwtPlot::yRight); qwtPlotCurveHallU.setSymbol(qwtPlotHallUSymbol); qwtPlotCurveResistivity.setSymbol(qwtPlotResistivitySymbol); ui->dataTableWidget->resizeColumnsToContents(); }
QwtSymbol *SAQwtPlotCurveItemSetWidget::makeSymbol(QwtSymbol::Style style) { if(nullptr == m_curveItem) { return nullptr; } const QwtSymbol* oldSymbol = m_curveItem->symbol(); QwtSymbol* newSymbol = nullptr; if(QwtSymbol::NoSymbol != style) { newSymbol = new QwtSymbol(style); if(nullptr == oldSymbol) { //初始没有符号,第一次设置 QColor penColor = m_curveItem->pen().color(); newSymbol->setPen(penColor); penColor.setAlpha(80); newSymbol->setBrush(QBrush(penColor)); newSymbol->setSize(6,6); } else { newSymbol->setPen(oldSymbol->pen()); newSymbol->setBrush(oldSymbol->brush()); newSymbol->setSize(oldSymbol->size()); } } return newSymbol; }
void PfPvPlot::configChanged() { setCanvasBackground(GColor(CPLOTBACKGROUND)); // frame with inverse of background QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Ellipse); sym->setSize(4); sym->setPen(QPen(Qt::red)); sym->setBrush(QBrush(Qt::red)); curve->setSymbol(sym); curve->setStyle(QwtPlotCurve::Dots); curve->setRenderHint(QwtPlotItem::RenderAntialiased); QPalette palette; palette.setBrush(QPalette::Window, QBrush(GColor(CPLOTBACKGROUND))); palette.setColor(QPalette::WindowText, GColor(CPLOTMARKER)); palette.setColor(QPalette::Text, GColor(CPLOTMARKER)); setPalette(palette); axisWidget(QwtPlot::xBottom)->setPalette(palette); axisWidget(QwtPlot::yLeft)->setPalette(palette); // use grid line color for mX, mY and CPcurve QPen marker = GColor(CPLOTMARKER); QPen cp = GColor(CCP); mX->setLinePen(marker); mY->setLinePen(marker); cpCurve->setPen(cp); setCL(appsettings->value(this, GC_CRANKLENGTH).toDouble() / 1000.0); replot(); }
void VectorPlot::addDotPlot(const MarkupQwtAdapter&adapter, QColor color, const QString &name, bool addToLegend) { QwtPlotCurve *curve = new QwtPlotCurve(name); QwtSymbol sym; sym.setPen(QColor(color)); sym.setBrush(QColor(color)); sym.setStyle(QwtSymbol::Rect); sym.setSize( QSize(1, 20) ); curve->setSymbol(sym); curve->setStyle(QwtPlotCurve::NoCurve); if(adapter.size() > 0) { setupPlot(adapter.boundingRect()); curve->setData(adapter); curve->attach(plot); } if(!legend) { return; } // Добавляем кривую в легенду QwtLegendItem *item = new QwtLegendItem(0); item->setText(curve->title()); item->setSymbol(sym); item->setIdentifierMode(QwtLegendItem::ShowLine | QwtLegendItem::ShowSymbol | QwtLegendItem::ShowText); legend->insert(curve, item); }
void PlotIterPath::setGrayPen() { QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setBrush(QBrush(Qt::gray)); sym.setPen(QPen(Qt::black, 1)); sym.setSize(10); iterPathPlot_.setSymbol(sym); iterPathPlot_.setPen(QPen(Qt::black, 3)); sym.setBrush(QBrush(Qt::red)); sym.setPen(QPen(Qt::red, 1)); sym.setSize(10); selectedIteratePlot_.setSymbol(sym); selectedLinePlot_.setPen(QPen(Qt::red, 3)); }
void PlotIterPath::setColorPen(const QColor &color) { QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setBrush(QBrush(color)); sym.setPen(QPen(color, 1)); sym.setSize(10); iterPathPlot_.setSymbol(sym); iterPathPlot_.setPen(QPen(color, 3)); sym.setBrush(QBrush(Qt::red)); sym.setPen(QPen(Qt::red, 1)); sym.setSize(10); selectedIteratePlot_.setSymbol(sym); selectedLinePlot_.setPen(QPen(Qt::red, 3)); }
SegmentInfo::SegmentInfo(const BinaryImageTreeItem *s): gammaStartIndex(0), gammaEndIndex(0), segment(s), arterySegment(NULL), sampleCurve(s->getName()), gammaCurve(s->getName()+ QObject::tr(" Gamma Fit")), patlakCurve(s->getName()), patlakRegression(s->getName() + QObject::tr(" linear Regression")), patlakCreated(false) { //get color of the segment QColor color = s->getColor(); //set color to the curve sampleCurve.setPen(QPen(color)); sampleCurve.setRenderHint(QwtPlotItem::RenderAntialiased, true); QwtSymbol symbol; //class for drawing symbols symbol.setStyle( QwtSymbol::Ellipse ); symbol.setSize(8); symbol.setPen(QPen(color)); symbol.setBrush(QBrush(color.darker(130))); //set the symbol to the curve sampleCurve.setSymbol( symbol ); //initialize curve data sampleCurve.setData( TimeDensityData() ); //create pen for gamma curve with dotted line QPen pen(color); pen.setStyle(Qt::DotLine); //set pen to gamma curve gammaCurve.setPen(pen); gammaCurve.setRenderHint(QwtPlotItem::RenderAntialiased, true); //initialize gamma curve data and hide it gammaCurve.setData( GammaFitData() ); gammaCurve.setVisible(false); //set style of the patlak curve patlakCurve.setRenderHint(QwtPlotItem::RenderAntialiased, true); patlakCurve.setStyle(QwtPlotCurve::NoCurve); symbol.setStyle( QwtSymbol::XCross ); symbol.setSize(8); symbol.setPen(QPen(color)); symbol.setBrush(QBrush(color.darker(130))); patlakCurve.setSymbol( symbol ); patlakRegression.setRenderHint(QwtPlotItem::RenderAntialiased, true); }
Graph::Graph(QWidget *parent) : QWidget(parent){ ui.setupUi(this); // Задаём положение окна по центру /*QDesktopWidget desktop; QRect rect = desktop.availableGeometry(desktop.primaryScreen()); QPoint center = rect.center(); center.setX(center.x() - (this->width()/2)); center.setY(center.y() - (this->height()/2)); move(center);*/ // Создаём окно this->setWindowTitle(QString::fromUtf8("График")); // Файл с настройками settings_read = new QSettings("settings.conf",QSettings::IniFormat); settings_write = new QSettings("settings.conf",QSettings::IniFormat); // Настройка отрисовки графика grid = new QwtPlotGrid; grid->enableXMin(true); grid->setMajPen(QPen(Qt::black,0,Qt::DotLine)); grid->setMinPen(QPen(Qt::gray,0,Qt::DotLine)); grid->attach(ui.qwtGraph); curveTimeForce = new QwtPlotCurve(); curveTimeForce->attach(ui.qwtGraph); QPen curvePen; curvePen.setStyle(Qt::DashLine); curvePen.setBrush(Qt::blue); curveTimeForce->setPen(curvePen); QwtSymbol symbolPoint; symbolPoint.setStyle(QwtSymbol::Rect); symbolPoint.setPen(QColor(Qt::blue)); symbolPoint.setSize(5); curveTimeForce->setSymbol(symbolPoint); // Установка единиц измерения силы connect( this->ui.rbAdc, SIGNAL( clicked() ), this, SLOT( rbAdcSet() ) ); connect( this->ui.rbNewton, SIGNAL( clicked() ), this, SLOT( rbNewtonSet() ) ); connect( this->ui.rbKgf, SIGNAL( clicked() ), this, SLOT( rbKgfSet() ) ); nPoints = 0; ui.rbAdc->setChecked(1); ui.qwtGraph->setAxisTitle(QwtPlot::yLeft,QString::fromUtf8("F, ед. ацп")); ui.qwtGraph->setAxisTitle(QwtPlot::xBottom,QString::fromUtf8("t, секунды")); // Загрузка настроек loadSettings(); }
void VectorPlot::addLinePlot(const VectorQwtAdapter &adapter) { setupPlot(adapter.boundingRect()); QwtPlotCurve *curve = new QwtPlotCurve(); QwtSymbol sym; sym.setStyle(QwtSymbol::Cross); sym.setPen(QColor(Qt::black)); sym.setSize(2); curve->setSymbol(sym); curve->setPen(QColor(Qt::darkGreen)); curve->setData(adapter); curve->attach(plot); }
PlotIterPath::PlotIterPath(QwtPlot *parent) : parent_(parent) { QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setBrush(QBrush(Qt::gray)); sym.setPen(QPen(Qt::black, 1)); sym.setSize(10); iterPathPlot_.setSymbol(sym); iterPathPlot_.setPen(QPen(Qt::black, 3)); sym.setStyle(QwtSymbol::Ellipse); sym.setBrush(QBrush(Qt::red)); sym.setPen(QPen(Qt::red, 1)); sym.setSize(10); selectedIteratePlot_.setSymbol(sym); selectedLinePlot_.setPen(QPen(Qt::red, 3)); iterPathPlot_.attach(parent_); selectedIteratePlot_.attach(parent_); selectedLinePlot_.attach(parent_); }
void Plot::insertCurve( const QString& title, const QVector<QPointF>& samples, const QColor &color ) { d_curve = new QwtPlotCurve( title ); d_curve->setRenderHint( QwtPlotItem::RenderAntialiased ); d_curve->setStyle( QwtPlotCurve::NoCurve ); d_curve->setLegendAttribute( QwtPlotCurve::LegendShowSymbol ); QwtSymbol *symbol = new QwtSymbol( QwtSymbol::XCross ); symbol->setSize( 4 ); symbol->setPen( QPen( color ) ); d_curve->setSymbol( symbol ); d_curve->setSamples( samples ); d_curve->attach( this ); }
void specCanvasItem::setSymbolPenColor(const QColor& newColor) { if(oldSymbol) { QPen newPen(oldSymbol->pen()) ; newPen.setColor(newColor) ; oldSymbol->setPen(newPen) ; } else { QwtSymbol* newSymbol = symbol() ? cloneSymbol(symbol()) : (new QwtSymbol) ; QPen newPen = newSymbol->pen() ; newPen.setColor(newColor) ; newSymbol->setPen(newPen) ; setSymbol(newSymbol) ; } }
PfPvPlot::PfPvPlot() : rideItem (NULL), cp_ (0), cad_ (85), cl_ (0.175), shade_zones(true) { setCanvasBackground(Qt::white); setAxisTitle(yLeft, "Average Effective Pedal Force (N)"); setAxisScale(yLeft, 0, 600); setAxisTitle(xBottom, "Circumferential Pedal Velocity (m/s)"); setAxisScale(xBottom, 0, 3); mX = new QwtPlotMarker(); mX->setLineStyle(QwtPlotMarker::VLine); mX->attach(this); mY = new QwtPlotMarker(); mY->setLineStyle(QwtPlotMarker::HLine); mY->attach(this); cpCurve = new QwtPlotCurve(); cpCurve->setRenderHint(QwtPlotItem::RenderAntialiased); cpCurve->attach(this); curve = new QwtPlotCurve(); QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setSize(6); sym.setPen(QPen(Qt::red)); sym.setBrush(QBrush(Qt::NoBrush)); curve->setSymbol(sym); curve->setStyle(QwtPlotCurve::Dots); curve->setRenderHint(QwtPlotItem::RenderAntialiased); curve->attach(this); boost::shared_ptr<QSettings> settings = GetApplicationSettings(); cl_ = settings->value(GC_CRANKLENGTH).toDouble() / 1000.0; recalc(); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimPlotCurve::updateCurveAppearance() { CVF_ASSERT(m_qwtPlotCurve); QColor curveColor(m_curveColor.value().rByte(), m_curveColor.value().gByte(), m_curveColor.value().bByte()); QwtSymbol* symbol = nullptr; if (m_pointSymbol() != RiuQwtSymbol::SYMBOL_NONE) { // QwtPlotCurve will take ownership of the symbol symbol = new RiuQwtSymbol(m_pointSymbol(), m_symbolLabel, m_symbolLabelPosition); symbol->setSize(m_symbolSize, m_symbolSize); symbol->setColor(curveColor); QColor symbolEdgeColor(m_symbolEdgeColor.value().rByte(), m_symbolEdgeColor.value().gByte(), m_symbolEdgeColor.value().bByte()); symbol->setPen(symbolEdgeColor); } m_qwtPlotCurve->setAppearance(m_lineStyle(), m_curveInterpolation(), m_curveThickness(), curveColor); m_qwtPlotCurve->setSymbol(symbol); m_qwtPlotCurve->setSymbolSkipPixelDistance(m_symbolSkipPixelDistance()); m_qwtPlotCurve->setErrorBarsColor(curveColor); // Make sure the legend lines are long enough to distinguish between line types. // Standard width in Qwt is 8 which is too short. // Use 10 and scale this by curve thickness + add space for displaying symbol. if (m_lineStyle() != RiuQwtPlotCurve::STYLE_NONE) { QSize legendIconSize = m_qwtPlotCurve->legendIconSize(); int symbolWidth = 0; if (symbol) { symbolWidth = symbol->boundingRect().size().width() + 2; } int width = std::max(10 * m_curveThickness, (symbolWidth * 3) / 2); legendIconSize.setWidth(width); m_qwtPlotCurve->setLegendIconSize(legendIconSize); } }
void IncrementalPlot::appendData(double *x, double *y, int size) { if (d_data == NULL) d_data = new CurveData; if (d_curve == NULL) { d_curve = new QwtPlotCurve("Data"); d_curve->setStyle(QwtPlotCurve::NoCurve); d_curve->setPaintAttribute(QwtPlotCurve::FilterPoints, true); const QColor &c = Qt::white; QwtSymbol *symbol = new QwtSymbol(QwtSymbol::Ellipse); symbol->setBrush(QBrush(c)); symbol->setPen(QPen(c)); symbol->setSize(QSize(6, 6)); d_curve->setSymbol(symbol); d_curve->attach(this); } d_data->append(x, y, size); d_curve->setRawSamples(d_data->x(), d_data->y(), d_data->count()); #ifdef __GNUC__ #warning better use QwtData #endif const bool cacheMode = qobject_cast<QwtPlotCanvas *>(canvas())->testPaintAttribute(QwtPlotCanvas::BackingStore); #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent // works on X11. This has an tremendous effect on the performance.. canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); #endif QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas *>(canvas()); plotCanvas->setPaintAttribute(QwtPlotCanvas::BackingStore, false); QPainter painter; QwtScaleMap xMap = plotCanvas->plot()->canvasMap(d_curve->xAxis()); QwtScaleMap yMap = plotCanvas->plot()->canvasMap(d_curve->yAxis()); d_curve->drawSeries(&painter, xMap, yMap, (d_curve->paintRect(xMap, yMap)), d_curve->dataSize() - size, d_curve->dataSize() -1); plotCanvas->setPaintAttribute(QwtPlotCanvas::BackingStore, cacheMode); #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false); #endif }
void FFTWidget::init() { setTitle("FFT"); hrBpm = 0; hrMarker = new QwtPlotMarker(); hrMarker->setLineStyle(QwtPlotMarker::VLine); hrMarker->setLinePen(QPen(QColor(255,255,255,100), 2, Qt::SolidLine)); QPen pen; pen.setWidth(2); pen.setColor(Qt::blue); QwtSymbol *symb = new QwtSymbol(QwtSymbol::Diamond); symb->setPen(pen); symb->setSize(10); hrMarker->setSymbol(symb); hrMarker->attach(this); hrMarker->setVisible(false); setAxisAutoScale(QwtPlot::yLeft, true); counter = 0; dX = QVector<double>(size, 0); dY = QVector<double>(size, 0); dYBuf = QVector<double>(size, 0); hamming = QVector<double>(size, 0); dataIn = QVector<double>(size, 0); sampleInterval = 1000/fS; p = fftw_plan_r2r_1d( size, dataIn.data(), dYBuf.data(), FFTW_DHT, FFTW_ESTIMATE ); for(int i=0;i<size;i++) { dX.replace(i, i*(fS/size)); double tmp = 0.54 - 0.46*(2*3.1415*i/size); hamming.replace(i, tmp); } pen.setColor(Qt::red); curve = new QwtPlotCurve(); curve->setPen(pen); curve->setRawSamples(dX.data(), dY.data(), size/2); curve->setRenderHint(QwtPlotItem::RenderAntialiased); curve->attach(this); }
Curve1() { setPen( QColor( 150, 150, 200 ), 2 ); setStyle( QwtPlotCurve::Lines ); QwtSplineCurveFitter *curveFitter = new QwtSplineCurveFitter(); curveFitter->setSplineSize( 150 ); setCurveFitter( curveFitter ); setCurveAttribute( QwtPlotCurve::Fitted, true ); QwtSymbol *symbol = new QwtSymbol( QwtSymbol::XCross ); symbol->setPen( Qt::yellow ); symbol->setSize( 7 ); setSymbol( symbol ); // somewhere to the left QTransform transform; transform.scale( 1.5, 1.0 ); transform.translate( 1.5, 3.0 ); setTransformation( transform ); }
void PfPvPlot::configChanged() { setCanvasBackground(GColor(CPLOTBACKGROUND)); // frame with inverse of background QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setSize(6); sym.setPen(GCColor::invert(GColor(CPLOTBACKGROUND))); sym.setBrush(QBrush(Qt::NoBrush)); curve->setSymbol(new QwtSymbol(sym)); curve->setStyle(QwtPlotCurve::Dots); curve->setRenderHint(QwtPlotItem::RenderAntialiased); // use grid line color for mX, mY and CPcurve QPen marker = GColor(CPLOTMARKER); QPen cp = GColor(CCP); mX->setLinePen(marker); mY->setLinePen(marker); cpCurve->setPen(cp); setCL(appsettings->value(this, GC_CRANKLENGTH).toDouble() / 1000.0); }
void QwtPlotPrintFilter::apply(QwtPlotItem *item) const { PrivateData::Cache &cache = *d_data->cache; switch(item->rtti()) { case QwtPlotItem::Rtti_PlotGrid: { QwtPlotGrid *grid = (QwtPlotGrid *)item; QPen pen = grid->majPen(); cache.gridColors[0] = pen.color(); pen.setColor(color(pen.color(), MajorGrid)); grid->setMajPen(pen); pen = grid->minPen(); cache.gridColors[1] = pen.color(); pen.setColor(color(pen.color(), MinorGrid)); grid->setMinPen(pen); break; } case QwtPlotItem::Rtti_PlotCurve: { QwtPlotCurve *c = (QwtPlotCurve *)item; QwtSymbol symbol = c->symbol(); QPen pen = symbol.pen(); cache.curveSymbolPenColors.insert(c, pen.color()); pen.setColor(color(pen.color(), CurveSymbol)); symbol.setPen(pen); QBrush brush = symbol.brush(); cache.curveSymbolBrushColors.insert(c, brush.color()); brush.setColor(color(brush.color(), CurveSymbol)); symbol.setBrush(brush); c->setSymbol(symbol); pen = c->pen(); cache.curveColors.insert(c, pen.color()); pen.setColor(color(pen.color(), Curve)); c->setPen(pen); break; } case QwtPlotItem::Rtti_PlotMarker: { QwtPlotMarker *m = (QwtPlotMarker *)item; QwtText label = m->label(); cache.markerFonts.insert(m, label.font()); label.setFont(font(label.font(), Marker)); cache.markerLabelColors.insert(m, label.color()); label.setColor(color(label.color(), Marker)); m->setLabel(label); QPen pen = m->linePen(); cache.markerLineColors.insert(m, pen.color()); pen.setColor(color(pen.color(), Marker)); m->setLinePen(pen); QwtSymbol symbol = m->symbol(); pen = symbol.pen(); cache.markerSymbolPenColors.insert(m, pen.color()); pen.setColor(color(pen.color(), MarkerSymbol)); symbol.setPen(pen); QBrush brush = symbol.brush(); cache.markerSymbolBrushColors.insert(m, brush.color()); brush.setColor(color(brush.color(), MarkerSymbol)); symbol.setBrush(brush); m->setSymbol(symbol); break; } default: break; } }
Variog_multiplot:: Variog_multiplot( const std::vector<Discrete_function>& df_vec, const QStringList& titles, QWidget *parent, const char *name ) : QwtPlot(parent) { if (name) setObjectName(name); //this->setWindowFlags( Qt::SubWindow|Qt::MSWindowsFixedSizeDialogHint); //------------ // configure the plotting area //use a light gray for the grid QwtPlotGrid * grid = new QwtPlotGrid(); grid->enableX(true); grid->setPen( QPen( QColor(150,150,150), 0, Qt::DotLine ) ); grid->attach(this); // configure the plot axis this->axisScaleEngine(QwtPlot::xBottom)->setReference(0); this->axisScaleEngine(QwtPlot::yLeft)->setReference(0); this->axisScaleEngine(QwtPlot::xBottom)->setMargins(0,0.5); this->axisScaleEngine(QwtPlot::yLeft)->setMargins(0,0.5); this->axisScaleEngine(QwtPlot::xBottom)->setAttributes(QwtScaleEngine::Floating | QwtScaleEngine::IncludeReference); this->axisScaleEngine(QwtPlot::yLeft)->setAttributes(QwtScaleEngine::Floating | QwtScaleEngine::IncludeReference); QFont axis_font = this->axisFont( QwtPlot::xBottom ); axis_font.setPointSize( 7 ); QwtText title("distance"); title.setFont(axis_font); this->setAxisTitle( QwtPlot::xBottom,title); //------------- this->setWindowTitle( "All Plots" ); typedef enum QwtSymbol::Style QwtStyleEnum; typedef enum Qt::PenStyle QtPenStyleEnum; unsigned int dot_styles[8] = { QwtSymbol::Ellipse, QwtSymbol::Rect, QwtSymbol::Diamond, QwtSymbol::DTriangle, QwtSymbol::UTriangle, QwtSymbol::RTriangle, QwtSymbol::Cross, QwtSymbol::XCross }; unsigned int line_styles[5] = {Qt::SolidLine, Qt::DashLine, Qt::DotLine, Qt::DashDotLine, Qt::DashDotDotLine }; /* if( !title.isEmpty() ) { QFont title_font; title_font.setPointSize( 8 ); this->setTitle( title ); this->setTitleFont( title_font ); this->setCaption( title ); } */ const float ymargin = 1.05; const float xmargin = 1.06; float ymax = -9e99; float ymin = 9e99; float xmax = -9e99; for( unsigned int plot_id = 0; plot_id < df_vec.size() ; plot_id++ ) { std::vector<double> x_vals = df_vec[plot_id].x_values(); std::vector<double> y_vals = df_vec[plot_id].y_values(); double* x = new double[x_vals.size()]; double* y = new double[x_vals.size()]; int actual_size = 0; for( int i=0 ; i < x_vals.size() ; i++ ) { if( GsTL::equals( x_vals[i], df_vec[plot_id].no_data_value(), 0.001 ) || GsTL::equals( y_vals[i], df_vec[plot_id].no_data_value(), 0.001 ) ) continue; x[actual_size] = x_vals[i]; y[actual_size] = y_vals[i]; actual_size++; } if( actual_size > 0 ) { float current_ymax = *(std::max_element( y, y+actual_size )); float current_ymin = *(std::min_element( y, y+actual_size )); float current_xmax = *(std::max_element( x, x+actual_size )); ymax = std::max(ymax, current_ymax ); ymin = std::min(ymin, current_ymin ); xmax = std::max(xmax, current_xmax ); } QwtPlotCurve * curve_id = new QwtPlotCurve(titles[plot_id]); curve_id->attach(this); curve_id->setData( x, y, actual_size ); QwtSymbol symbol; // The following line uses an awful cast from int to enum !! // Awful, but it will stay until I find a more elegant way of looping // through all the qwt styles. symbol.setStyle( static_cast<QwtStyleEnum>(dot_styles[plot_id%8]) ); symbol.setPen( QPen(Qt::black, 1 ) ); symbol.setSize(6); curve_id->setSymbol(symbol); curve_id->setStyle(QwtPlotCurve::Lines); curve_id->setPen( QPen(Qt::darkGray, 0, static_cast<QtPenStyleEnum>(line_styles[plot_id%5]) ) ); delete [] x; delete [] y; } if( ymax == 0 && ymin == 0 ) this->setAxisAutoScale( QwtPlot::yLeft ); else this->setAxisScale( QwtPlot::yLeft, ymin*(2-ymargin), ymax*ymargin ); if( xmax > 0 ) { this->setAxisScale( QwtPlot::xBottom, 0, xmax*xmargin ); } QwtLegend * legend = new QwtLegend(); this->insertLegend(legend); this->replot(); }
// We are going to support multiple models; normal, normal-skew, linear // So for now lets make it a parameter for the model curve creation // The model may end up being comprised of 'sub models' for each fibre type void MUPlot::setModel(int model) { this->model = model; // first lets clear any curves we shouldn't be displaying // no model curve if not power ! if (modelCurve) { modelCurve->detach(); delete modelCurve; modelCurve = NULL; } if (slowCurve) { slowCurve->detach(); delete slowCurve; slowCurve = NULL; } if (slowHandle) { slowHandle->detach(); delete slowHandle; slowHandle = NULL; } if (slowLine) { slowLine->detach(); delete slowLine; slowLine = NULL; } if (fastCurve) { fastCurve->detach(); delete fastCurve; fastCurve = NULL; } if (fastHandle) { fastHandle->detach(); delete fastHandle; fastHandle = NULL; } if (fastLine) { fastLine->detach(); delete fastLine; fastLine = NULL; } if (mmpCurve) { mmpCurve->detach(); delete mmpCurve; mmpCurve = NULL; } switch (model) { case 0 : // no model - do nothing { } break; case 2 : // 2 Normal distribution -- drops through to case 1 below { fastCurve = new QwtPlotCurve( "MU Distribution" ); fastCurve->setData(fastNormal = new MUNormal(MU_FASTMEAN, 0.05f)); fastCurve->attach(this); QColor handleColor = QColor(Qt::magenta).darker(30); // customise (?) handleColor.setAlpha(64); // now a mean line fastLine = new QwtPlotMarker(); fastLine->setLineStyle(QwtPlotMarker::VLine); fastLine->setLinePen(QPen(QColor(handleColor), 0, Qt::SolidLine)); fastLine->setValue(MU_FASTMEAN, 0); // mean fastLine->setZ(50); fastLine->attach(this); // now add a handle QColor color = GColor(CPLOTBACKGROUND); double x = MU_FASTMEAN; // mean is ok double y = 0.05f * 40.0f; // variance scaled to w(x) QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Rect); sym->setSize(8 *dpiXFactor); sym->setPen(QPen(handleColor)); // customise ? sym->setBrush(QBrush(color)); fastHandle = new QwtPlotMarker(); fastHandle->setValue(x, y); fastHandle->setYAxis(yLeft); fastHandle->setZ(100); fastHandle->setSymbol(sym); fastHandle->attach(this); } // intentional fallthrough case 1 : // Normal distribution { slowCurve = new QwtPlotCurve( "MU Distribution" ); slowCurve->setData(slowNormal = new MUNormal(MU_SLOWMEAN, 0.05f)); slowCurve->attach(this); QColor handleColor = GColor(CCP).darker(30); handleColor.setAlpha(64); // now a mean line slowLine = new QwtPlotMarker(); slowLine->setLineStyle(QwtPlotMarker::VLine); slowLine->setLinePen(QPen(QColor(handleColor), 0, Qt::SolidLine)); slowLine->setValue(MU_SLOWMEAN, 0); // mean slowLine->setZ(50); slowLine->attach(this); // now add a handle QColor color = GColor(CPLOTBACKGROUND); double x = MU_SLOWMEAN; // mean is ok double y = 0.05f * 40.0f; // variance scaled to w(x) QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Rect); sym->setSize(8 *dpiXFactor); sym->setPen(QPen(handleColor)); // customise ? sym->setBrush(QBrush(color)); slowHandle = new QwtPlotMarker(); slowHandle->setValue(x, y); slowHandle->setYAxis(yLeft); slowHandle->setZ(100); slowHandle->setSymbol(sym); slowHandle->attach(this); // mmp curve mmpCurve = new QwtPlotCurve( "MU Distribution" ); mmpCurve->attach(parent->cpPlot); } break; } // set the colors etc for our curve(s) if (fastCurve) { // antialias bool antialias = appsettings->value(this, GC_ANTIALIAS, false).toBool(); if (antialias) fastCurve->setRenderHint(QwtPlotItem::RenderAntialiased); // color and brush QColor color = QColor(Qt::magenta); //XXX customise QPen pen(color); pen.setWidth(1.0); color.setAlpha(80); QBrush brush(color); fastCurve->setPen(pen); fastCurve->setBrush(brush); } if (slowCurve) { // antialias bool antialias = appsettings->value(this, GC_ANTIALIAS, false).toBool(); if (antialias) slowCurve->setRenderHint(QwtPlotItem::RenderAntialiased); // color and brush QColor color = GColor(CCP); // customise ? QPen pen(color); pen.setWidth(1.0); color.setAlpha(80); QBrush brush(color); slowCurve->setPen(pen); slowCurve->setBrush(brush); QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Ellipse); sym->setSize(4 *dpiXFactor); sym->setPen(QPen(Qt::yellow)); // customise ? sym->setBrush(QBrush(Qt::yellow)); mmpCurve->setPen(QPen(Qt::yellow)); mmpCurve->setSymbol(sym); mmpCurve->setBrush(Qt::NoBrush); // and refresh the MMP setMUSet(); } if (model) { modelCurve = new QwtPlotCurve( "Total Distribution" ); modelCurve->setData(this); // we provide the data too! QColor color = QColor(Qt::yellow); //XXX customise QPen pen(color); pen.setWidth(1.0); color.setAlpha(80); modelCurve->setPen(pen); modelCurve->setBrush(Qt::NoBrush); modelCurve->attach(this); } replot(); }
/*! Reset color and fonts of a plot \sa QwtPlotPrintFilter::apply */ void QwtPlotPrintFilter::reset(QwtPlot *plot) const { if ( d_cache == 0 ) return; QFont *font; QColor *color; if ( plot->d_lblTitle ) { QPalette palette = plot->d_lblTitle->palette(); palette.setColor( QPalette::Active, QColorGroup::Foreground, d_cache->titleColor); plot->d_lblTitle->setPalette(palette); plot->d_lblTitle->setFont(d_cache->titleFont); } if ( plot->d_legend ) { QIntDictIterator<QWidget> it = plot->d_legend->itemIterator(); for ( QWidget *w = it.toFirst(); w != 0; w = ++it) { const int key = it.currentKey(); font = d_cache->legendFonts.find(key); if ( font ) w->setFont(*font); if ( w->inherits("QwtLegendButton") ) { QwtLegendButton *btn = (QwtLegendButton *)w; QwtSymbol symbol = btn->symbol(); color = d_cache->curveSymbolPenColors.find(key); if ( color ) { QPen pen = symbol.pen(); pen.setColor(*color); symbol.setPen(pen); } color = d_cache->curveSymbolBrushColors.find(key); if ( color ) { QBrush brush = symbol.brush(); brush.setColor(*color); symbol.setBrush(brush); } btn->setSymbol(symbol); color = d_cache->curveColors.find(key); if ( color ) { QPen pen = btn->curvePen(); pen.setColor(*color); btn->setCurvePen(pen); } } } } for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { QwtScale *scale = plot->d_scale[axis]; if ( scale ) { QPalette palette = scale->palette(); palette.setColor(QPalette::Active, QColorGroup::Foreground, d_cache->scaleColor[axis]); scale->setPalette(palette); scale->setFont(d_cache->scaleFont[axis]); scale->setTitleColor(d_cache->scaleTitleColor[axis]); scale->setTitleFont(d_cache->scaleTitleFont[axis]); int startDist, endDist; scale->minBorderDist(startDist, endDist); scale->setBorderDist(startDist, endDist); } } plot->setBackgroundColor(d_cache->widgetBackground); plot->setCanvasBackground(d_cache->canvasBackground); QPen pen = plot->d_grid->majPen(); pen.setColor(d_cache->gridColors[0]); plot->d_grid->setMajPen(pen); pen = plot->d_grid->minPen(); pen.setColor(d_cache->gridColors[1]); plot->d_grid->setMinPen(pen); QIntDictIterator<QwtPlotCurve> itc(*plot->d_curves); for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc ) { const int key = itc.currentKey(); QwtSymbol symbol = c->symbol(); color = d_cache->curveSymbolPenColors.find(key); if ( color ) { QPen pen = symbol.pen(); pen.setColor(*color); symbol.setPen(pen); } color = d_cache->curveSymbolBrushColors.find(key); if ( color ) { QBrush brush = symbol.brush(); brush.setColor(*color); symbol.setBrush(brush); } c->setSymbol(symbol); color = d_cache->curveColors.find(key); if ( color ) { QPen pen = c->pen(); pen.setColor(*color); c->setPen(pen); } } QIntDictIterator<QwtPlotMarker> itm(*plot->d_markers); for (QwtPlotMarker *m = itm.toFirst(); m != 0; m = ++itm ) { const int key = itm.currentKey(); font = d_cache->markerFonts.find(key); if ( font ) m->setFont(*font); color = d_cache->markerLabelColors.find(key); if ( color ) { QPen pen = m->labelPen(); pen.setColor(*color); m->setLabelPen(pen); } color = d_cache->markerLineColors.find(key); if ( color ) { QPen pen = m->linePen(); pen.setColor(*color); m->setLinePen(pen); } QwtSymbol symbol = m->symbol(); color = d_cache->markerSymbolPenColors.find(key); if ( color ) { QPen pen = symbol.pen(); pen.setColor(*color); symbol.setPen(pen); } color = d_cache->markerSymbolBrushColors.find(key); if ( color ) { QBrush brush = symbol.brush(); brush.setColor(*color); symbol.setBrush(brush); } m->setSymbol(symbol); } QwtPlotPrintFilter *that = (QwtPlotPrintFilter *)this; delete that->d_cache; that->d_cache = 0; }
/*! Change color and fonts of a plot \sa QwtPlotPrintFilter::apply */ void QwtPlotPrintFilter::apply(QwtPlot *plot) const { QwtPlotPrintFilter *that = (QwtPlotPrintFilter *)this; delete that->d_cache; that->d_cache = new QwtPlotPrintFilterCache; QwtPlotPrintFilterCache &cache = *that->d_cache; if ( plot->d_lblTitle ) { QPalette palette = plot->d_lblTitle->palette(); cache.titleColor = palette.color( QPalette::Active, QColorGroup::Foreground); palette.setColor(QPalette::Active, QColorGroup::Foreground, color(cache.titleColor, Title)); plot->d_lblTitle->setPalette(palette); cache.titleFont = plot->d_lblTitle->font(); plot->d_lblTitle->setFont(font(cache.titleFont, Title)); } if ( plot->d_legend ) { QIntDictIterator<QWidget> it = plot->d_legend->itemIterator(); for ( QWidget *w = it.toFirst(); w != 0; w = ++it) { const int key = it.currentKey(); cache.legendFonts.insert(it.currentKey(), new QFont(w->font())); w->setFont(font(w->font(), Legend, key)); if ( w->inherits("QwtLegendButton") ) { QwtLegendButton *btn = (QwtLegendButton *)w; QwtSymbol symbol = btn->symbol(); QPen pen = symbol.pen(); QBrush brush = symbol.brush(); pen.setColor(color(pen.color(), CurveSymbol, key)); brush.setColor(color(brush.color(), CurveSymbol, key)); symbol.setPen(pen); symbol.setBrush(brush); btn->setSymbol(symbol); pen = btn->curvePen(); pen.setColor(color(pen.color(), Curve, key)); btn->setCurvePen(pen); } } } for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { QwtScale *scale = plot->d_scale[axis]; if ( scale ) { cache.scaleColor[axis] = scale->palette().color( QPalette::Active, QColorGroup::Foreground); QPalette palette = scale->palette(); palette.setColor(QPalette::Active, QColorGroup::Foreground, color(cache.scaleColor[axis], AxisScale, axis)); scale->setPalette(palette); cache.scaleFont[axis] = scale->font(); scale->setFont(font(cache.scaleFont[axis], AxisScale, axis)); cache.scaleTitleColor[axis] = scale->titleColor(); scale->setTitleColor( color(cache.scaleTitleColor[axis], AxisTitle, axis)); cache.scaleTitleFont[axis] = scale->titleFont(); scale->setTitleFont( font(cache.scaleTitleFont[axis], AxisTitle, axis)); int startDist, endDist; scale->minBorderDist(startDist, endDist); scale->setBorderDist(startDist, endDist); } } cache.widgetBackground = plot->backgroundColor(); plot->setBackgroundColor(color(cache.widgetBackground, WidgetBackground)); cache.canvasBackground = plot->canvasBackground(); plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground)); QPen pen = plot->d_grid->majPen(); cache.gridColors[0] = pen.color(); pen.setColor(color(pen.color(), MajorGrid)); plot->d_grid->setMajPen(pen); pen = plot->d_grid->minPen(); cache.gridColors[1] = pen.color(); pen.setColor(color(pen.color(), MinorGrid)); plot->d_grid->setMinPen(pen); QIntDictIterator<QwtPlotCurve> itc(*plot->d_curves); for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc ) { const int key = itc.currentKey(); QwtSymbol symbol = c->symbol(); QPen pen = symbol.pen(); cache.curveSymbolPenColors.insert(key, new QColor(pen.color())); pen.setColor(color(pen.color(), CurveSymbol, key)); symbol.setPen(pen); QBrush brush = symbol.brush(); cache.curveSymbolBrushColors.insert(key, new QColor(brush.color())); brush.setColor(color(brush.color(), CurveSymbol, key)); symbol.setBrush(brush); c->setSymbol(symbol); pen = c->pen(); cache.curveColors.insert(key, new QColor(pen.color())); pen.setColor(color(pen.color(), Curve, key)); c->setPen(pen); } QIntDictIterator<QwtPlotMarker> itm(*plot->d_markers); for (QwtPlotMarker *m = itm.toFirst(); m != 0; m = ++itm ) { const int key = itm.currentKey(); cache.markerFonts.insert(key, new QFont(m->font())); m->setFont(font(m->font(), Marker, key)); QPen pen = m->labelPen(); cache.markerLabelColors.insert(key, new QColor(pen.color())); pen.setColor(color(pen.color(), Marker, key)); m->setLabelPen(pen); pen = m->linePen(); cache.markerLineColors.insert(key, new QColor(pen.color())); pen.setColor(color(pen.color(), Marker, key)); m->setLinePen(pen); QwtSymbol symbol = m->symbol(); pen = symbol.pen(); cache.markerSymbolPenColors.insert(key, new QColor(pen.color())); pen.setColor(color(pen.color(), MarkerSymbol, key)); symbol.setPen(pen); QBrush brush = symbol.brush(); cache.markerSymbolBrushColors.insert(key, new QColor(brush.color())); brush.setColor(color(brush.color(), MarkerSymbol, key)); symbol.setBrush(brush); m->setSymbol(symbol); } }
void ScatterPlot::setData (ScatterSettings *settings) { // get application settings cranklength = appsettings->value(this, GC_CRANKLENGTH, 0.0).toDouble() / 1000.0; // if there are no settings or incomplete settings // create a null data plot if (settings == NULL || settings->ride == NULL || settings->ride->ride() == NULL || settings->x == 0 || settings->y == 0 ) { return; } // if its not setup or no settings exist default to 175mm cranks if (cranklength == 0.0) cranklength = 0.175; // // Create Main Plot dataset - used to frame intervals // int points=0; x.clear(); y.clear(); x.resize(settings->ride->ride()->dataPoints().count()); y.resize(settings->ride->ride()->dataPoints().count()); double maxY = maxX = -65535; double minY = minX = 65535; foreach(const RideFilePoint *point, settings->ride->ride()->dataPoints()) { double xv = x[points] = pointType(point, settings->x, context->athlete->useMetricUnits, cranklength); double yv = y[points] = pointType(point, settings->y, context->athlete->useMetricUnits, cranklength); // skip zeroes? if (!(settings->ignore && (x[points] == 0 || y[points] == 0))) { points++; if (yv > maxY) maxY = yv; if (yv < minY) minY = yv; if (xv > maxX) maxX = xv; if (xv < minX) minX = xv; } } QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setSize(6); sym.setPen(GCColor::invert(GColor(CPLOTBACKGROUND))); sym.setBrush(QBrush(Qt::NoBrush)); QPen p; p.setColor(GColor(CPLOTSYMBOL)); sym.setPen(p); // wipe away existing if (all) { all->detach(); delete all; } // setup the framing curve if (settings->frame) { all = new QwtPlotCurve(); all->setSymbol(new QwtSymbol(sym)); all->setStyle(QwtPlotCurve::Dots); all->setRenderHint(QwtPlotItem::RenderAntialiased); all->setData(x.constData(), y.constData(), points); all->attach(this); } else { all = NULL; } QPen gridPen(GColor(CPLOTGRID)); gridPen.setStyle(Qt::DotLine); if (grid) { grid->detach(); delete grid; } if (settings->gridlines) { grid = new QwtPlotGrid(); grid->setPen(gridPen); grid->enableX(true); grid->enableY(true); grid->attach(this); } else { grid = NULL; } setAxisTitle(yLeft, describeType(settings->y, true, useMetricUnits)); setAxisTitle(xBottom, describeType(settings->x, true, useMetricUnits)); // truncate PfPv values to make easier to read if (settings->y == MODEL_AEPF) setAxisScale(yLeft, 0, 600); else setAxisScale(yLeft, minY, maxY); if (settings->x == MODEL_CPV) setAxisScale(xBottom, 0, 3); else setAxisScale(xBottom, minX, maxX); // // Create Interval Plot dataset - used to frame intervals // // clear out any interval curves which are presently defined if (intervalCurves.size()) { QListIterator<QwtPlotCurve *> i(intervalCurves); while (i.hasNext()) { QwtPlotCurve *curve = i.next(); curve->detach(); delete curve; } } intervalCurves.clear(); // which ones are highlighted then? QVector<int> intervals; QMap<int,int> displaySequence; for (int child=0; child<context->athlete->allIntervalItems()->childCount(); child++) { IntervalItem *current = dynamic_cast<IntervalItem *>(context->athlete->allIntervalItems()->child(child)); if ((current != NULL) && current->isSelected()) { intervals.append(child); displaySequence.insert(current->displaySequence, intervals.count()-1); } } if (intervals.count() > 0) { // interval data in here QVector<QVector<double> > xvals(intervals.count()); // array of curve x arrays QVector<QVector<double> > yvals(intervals.count()); // array of curve x arrays QVector<int> points(intervals.count()); // points in eac curve // extract interval data foreach(const RideFilePoint *point, settings->ride->ride()->dataPoints()) { double x = pointType(point, settings->x, useMetricUnits, cranklength); double y = pointType(point, settings->y, useMetricUnits, cranklength); if (!(settings->ignore && (x == 0 && y ==0))) { // which interval is it in? for (int idx=0; idx<intervals.count(); idx++) { IntervalItem *current = dynamic_cast<IntervalItem *>(context->athlete->allIntervalItems()->child(intervals[idx])); if (point->secs+settings->ride->ride()->recIntSecs() > current->start && point->secs< current->stop) { xvals[idx].append(x); yvals[idx].append(y); points[idx]++; } } } } // now we have the interval data lets create the curves QMapIterator<int, int> order(displaySequence); while (order.hasNext()) { order.next(); int idx = order.value(); QPen pen; QColor intervalColor; intervalColor.setHsv((255/context->athlete->allIntervalItems()->childCount()) * (intervals[idx]), 255,255); pen.setColor(intervalColor); sym.setPen(pen); QwtPlotCurve *curve = new QwtPlotCurve(); curve->setSymbol(new QwtSymbol(sym)); curve->setStyle(QwtPlotCurve::Dots); curve->setRenderHint(QwtPlotItem::RenderAntialiased); curve->setData(xvals[idx].constData(), yvals[idx].constData(), points[idx]); curve->attach(this); intervalCurves.append(curve); } }
void QwtPlotPrintFilter::reset(QwtPlotItem *item) const { if ( d_data->cache == 0 ) return; const PrivateData::Cache &cache = *d_data->cache; switch(item->rtti()) { case QwtPlotItem::Rtti_PlotGrid: { QwtPlotGrid *grid = (QwtPlotGrid *)item; QPen pen = grid->majPen(); pen.setColor(cache.gridColors[0]); grid->setMajPen(pen); pen = grid->minPen(); pen.setColor(cache.gridColors[1]); grid->setMinPen(pen); break; } case QwtPlotItem::Rtti_PlotCurve: { QwtPlotCurve *c = (QwtPlotCurve *)item; QwtSymbol symbol = c->symbol(); if ( cache.curveSymbolPenColors.contains(c) ) { symbol.setPen(cache.curveSymbolPenColors[c]); } if ( cache.curveSymbolBrushColors.contains(c) ) { QBrush brush = symbol.brush(); brush.setColor(cache.curveSymbolBrushColors[c]); symbol.setBrush(brush); } c->setSymbol(symbol); if ( cache.curveColors.contains(c) ) { QPen pen = c->pen(); pen.setColor(cache.curveColors[c]); c->setPen(pen); } break; } case QwtPlotItem::Rtti_PlotMarker: { QwtPlotMarker *m = (QwtPlotMarker *)item; if ( cache.markerFonts.contains(m) ) { QwtText label = m->label(); label.setFont(cache.markerFonts[m]); m->setLabel(label); } if ( cache.markerLabelColors.contains(m) ) { QwtText label = m->label(); label.setColor(cache.markerLabelColors[m]); m->setLabel(label); } if ( cache.markerLineColors.contains(m) ) { QPen pen = m->linePen(); pen.setColor(cache.markerLineColors[m]); m->setLinePen(pen); } QwtSymbol symbol = m->symbol(); if ( cache.markerSymbolPenColors.contains(m) ) { QPen pen = symbol.pen(); pen.setColor(cache.markerSymbolPenColors[m]); symbol.setPen(pen); } if ( cache.markerSymbolBrushColors.contains(m) ) { QBrush brush = symbol.brush(); brush.setColor(cache.markerSymbolBrushColors[m]); symbol.setBrush(brush); } m->setSymbol(symbol); break; } default: break; } }
void ObserverGraphic::setAttributes(const QStringList &attribs, const QStringList &curveTitles, /*const*/ QStringList &legKeys, /*const*/ QStringList &legAttribs) { attribList = attribs; InternalCurve *interCurve = 0; QColor color; int attrSize = attribList.size(); // Ignores the attribute of the x axis if (observerType == TObsGraphic) attrSize--; for (int i = 0; i < attrSize; i++) { interCurve = new InternalCurve(attribList.at(i), plotter); if (interCurve) { if (i < curveTitles.size()) interCurve->plotCurve->setTitle(curveTitles.at(i)); else interCurve->plotCurve->setTitle(QString("$curve %1").arg(i + 1)); internalCurves->insert(attribList.at(i), interCurve); // Sets a random color for the created curve color = QColor::fromHsvF(hueValues[(int)(qrand() % HUE_COUNT)], 1, 1); interCurve->plotCurve->setPen(color); interCurve->plotCurve->setLegendAttribute(QwtPlotCurve::LegendShowLine); int width = 0, style = 0, symbol = 0, colorBar = 0, num = 0, size = 0, penstyle = 0; width = legKeys.indexOf(WIDTH); style = legKeys.indexOf(STYLE); symbol = legKeys.indexOf(SYMBOL); size = legKeys.indexOf(SIZE_); penstyle = legKeys.indexOf(PENSTYLE); colorBar = legKeys.indexOf(COLOR_BAR); if ((!legAttribs.isEmpty()) && (colorBar > -1)) { QString aux; QStringList colorStrList; QPen pen; aux = legAttribs.at(colorBar).mid(0, legAttribs.at(colorBar).indexOf(COLOR_BAR_SEP)); colorStrList = aux.split(COLORS_SEP, QString::SkipEmptyParts) .first().split(ITEM_SEP).first().split(COMP_COLOR_SEP); // Retrieves the last colorBar value // colorStrList = aux.split(COLORS_SEP, QString::SkipEmptyParts) // .last().split(ITEM_SEP).first().split(COMP_COLOR_SEP); // color color.setRed(colorStrList.at(0).toInt()); color.setGreen(colorStrList.at(1).toInt()); color.setBlue(colorStrList.at(2).toInt()); // width num = legAttribs.at(width).toInt(); pen = QPen(color); pen.setWidth((num > 0) ? num : 1); interCurve->plotCurve->setPen(pen); // pen num = legAttribs.at(penstyle).toInt(); pen.setStyle((Qt::PenStyle) num); interCurve->plotCurve->setPen(pen); // style num = legAttribs.at(style).toInt(); interCurve->plotCurve->setStyle((QwtPlotCurve::CurveStyle) num); // symbol num = legAttribs.at(symbol).toInt(); QwtSymbol* qwtSymbol = new QwtSymbol; qwtSymbol->setStyle((QwtSymbol::Style) num); qwtSymbol->setPen(pen); if ((QwtSymbol::Style) num !=(QwtSymbol::Style) -1) { interCurve->plotCurve->setLegendAttribute(QwtPlotCurve::LegendShowSymbol); } //size num = legAttribs.at(size).toInt(); qwtSymbol->setSize(num); if (qwtSymbol->brush().style() != Qt::NoBrush) qwtSymbol->setBrush(pen.color()); interCurve->plotCurve->setSymbol(qwtSymbol); for (int j = 0; j < LEGEND_ITENS; j++) { legKeys.removeFirst(); legAttribs.removeFirst(); } } } else { if (execModes != Quiet) qWarning("%s", qPrintable(TerraMEObserver::MEMORY_ALLOC_FAILED)); } } plotter->setInternalCurves(internalCurves->values()); }
/*! Change color and fonts of a plot \sa apply() */ void QwtPlotPrintFilter::apply(QwtPlot *plot) const { const bool doAutoReplot = plot->autoReplot(); plot->setAutoReplot(false); delete d_data->cache; d_data->cache = new PrivateData::Cache; PrivateData::Cache &cache = *d_data->cache; if ( plot->titleLabel() ) { QPalette palette = plot->titleLabel()->palette(); cache.titleColor = palette.color( QPalette::Active, Palette::Text); palette.setColor(QPalette::Active, Palette::Text, color(cache.titleColor, Title)); plot->titleLabel()->setPalette(palette); cache.titleFont = plot->titleLabel()->font(); plot->titleLabel()->setFont(font(cache.titleFont, Title)); } if ( plot->legend() ) { #if QT_VERSION < 0x040000 QValueList<QWidget *> list = plot->legend()->legendItems(); for ( QValueListIterator<QWidget *> it = list.begin(); it != list.end(); ++it ) #else QList<QWidget *> list = plot->legend()->legendItems(); for ( QList<QWidget*>::iterator it = list.begin(); it != list.end(); ++it ) #endif { QWidget *w = *it; cache.legendFonts.insert(w, w->font()); w->setFont(font(w->font(), Legend)); if ( w->inherits("QwtLegendItem") ) { QwtLegendItem *label = (QwtLegendItem *)w; QwtSymbol symbol = label->symbol(); QPen pen = symbol.pen(); QBrush brush = symbol.brush(); pen.setColor(color(pen.color(), CurveSymbol)); brush.setColor(color(brush.color(), CurveSymbol)); symbol.setPen(pen); symbol.setBrush(brush); label->setSymbol(symbol); pen = label->curvePen(); pen.setColor(color(pen.color(), Curve)); label->setCurvePen(pen); } } } for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { QwtScaleWidget *scaleWidget = plot->axisWidget(axis); if ( scaleWidget ) { cache.scaleColor[axis] = scaleWidget->palette().color( QPalette::Active, Palette::Foreground); QPalette palette = scaleWidget->palette(); palette.setColor(QPalette::Active, Palette::Foreground, color(cache.scaleColor[axis], AxisScale)); scaleWidget->setPalette(palette); cache.scaleFont[axis] = scaleWidget->font(); scaleWidget->setFont(font(cache.scaleFont[axis], AxisScale)); cache.scaleTitle[axis] = scaleWidget->title(); QwtText scaleTitle = scaleWidget->title(); if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextColor) ) { cache.scaleTitleColor[axis] = scaleTitle.color(); scaleTitle.setColor( color(cache.scaleTitleColor[axis], AxisTitle)); } if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextFont) ) { cache.scaleTitleFont[axis] = scaleTitle.font(); scaleTitle.setFont( font(cache.scaleTitleFont[axis], AxisTitle)); } scaleWidget->setTitle(scaleTitle); int startDist, endDist; scaleWidget->getBorderDistHint(startDist, endDist); scaleWidget->setBorderDist(startDist, endDist); } } if ( hasBackgroundColor(plot) ) { QPalette p = plot->palette(); cache.widgetBackground = plot->palette().color( QPalette::Active, Palette::Background); p.setColor(QPalette::Active, Palette::Background, color(cache.widgetBackground, WidgetBackground)); plot->setPalette(p); } if ( hasBackgroundColor(plot->canvas())) { cache.canvasBackground = plot->canvasBackground(); plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground)); } const QwtPlotItemList& itmList = plot->itemList(); for ( QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); ++it ) { apply(*it); } plot->setAutoReplot(doAutoReplot); }
void QcepPlot::setPlotCurveStyle(int index, QwtPlotCurve *curve) { const int nColors = 10; const int nSymbols = 4; const int nStyles = 3; int colorIndex = index % nColors; int symbolIndex = (index / nColors) % nSymbols; int styleIndex = (index / (nColors * nSymbols)) % nStyles; QPen pen; QwtSymbol *symb = new QwtSymbol(); QBrush brush; switch (colorIndex) { case 0: pen = QPen(QColor(255,0,0)); // red break; case 1: pen = QPen(QColor(255,170,0)); // Orange break; case 2: pen = QPen(QColor(255,232,137)); // Yellow break; case 3: pen = QPen(QColor(0,255,0)); // Green break; case 4: pen = QPen(QColor(0,170,0)); // Dk green break; case 5: pen = QPen(QColor(0,255,255)); // Cyan break; case 6: pen = QPen(QColor(0,170,255)); // Sea blue break; case 7: pen = QPen(QColor(0,0,255)); // Blue break; case 8: pen = QPen(QColor(145,0,255)); // Violet break; case 9: pen = QPen(QColor(255,0,255)); // Magenta break; } switch (styleIndex) { case 0: pen.setStyle(Qt::SolidLine); break; case 1: pen.setStyle(Qt::DashLine); break; case 2: pen.setStyle(Qt::DotLine); break; case 3: pen.setStyle(Qt::DashDotLine); break; } symb->setPen(pen); symb->setBrush(QBrush(pen.color())); symb->setSize(5,5); switch (symbolIndex) { case 0: symb->setStyle(QwtSymbol::Ellipse); break; case 1: symb->setStyle(QwtSymbol::Rect); break; case 2: symb->setStyle(QwtSymbol::Triangle); break; case 3: symb->setStyle(QwtSymbol::DTriangle); break; } curve -> setPen(pen); curve -> setSymbol(symb); }
void PlotCurve::restoreCurveLayout(const QStringList &lst) { QStringList::const_iterator line = lst.begin(); for (++line; line != lst.end(); ++line) { QString s = *line; if (s == "<Pen>") { QPen pen; while (s != "</Pen>") { s = (*(++line)).trimmed(); if (s.contains("<Color>")) pen.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) pen.setStyle(Graph::getPenStyle( s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Width>")) pen.setWidthF(s.remove("<Width>").remove("</Width>").toDouble()); } setPen(pen); } else if (s == "<Brush>") { QBrush brush; while (s != "</Brush>") { s = (*(++line)).trimmed(); if (s.contains("<Color>")) brush.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) brush.setStyle(PatternBox::brushStyle( s.remove("<Style>").remove("</Style>").toInt())); } setBrush(brush); } else if (s == "<Symbol>") { QwtSymbol symbol; while (s != "</Symbol>") { s = (*(++line)).trimmed(); if (s.contains("<Style>")) symbol.setStyle( SymbolBox::style(s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Size>")) symbol.setSize( (QwtSymbol::Style)s.remove("<Size>").remove("</Size>").toInt()); else if (s == "<SymbolPen>") { QPen pen; while (s != "</SymbolPen>") { s = (*(++line)).trimmed(); if (s.contains("<Color>")) pen.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) pen.setStyle(Graph::getPenStyle( s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Width>")) pen.setWidthF(s.remove("<Width>").remove("</Width>").toDouble()); } symbol.setPen(pen); } else if (s == "<SymbolBrush>") { QBrush brush; while (s != "</SymbolBrush>") { s = (*(++line)).trimmed(); if (s.contains("<Color>")) brush.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) brush.setStyle(PatternBox::brushStyle( s.remove("<Style>").remove("</Style>").toInt())); } symbol.setBrush(brush); } setSymbol(symbol); } } else if (s.contains("<xAxis>")) setXAxis(s.remove("<xAxis>").remove("</xAxis>").toInt()); else if (s.contains("<yAxis>")) setYAxis(s.remove("<yAxis>").remove("</yAxis>").toInt()); else if (s.contains("<Visible>")) setVisible(s.remove("<Visible>").remove("</Visible>").toInt()); } }
/*! Reset color and fonts of a plot \sa apply() */ void QwtPlotPrintFilter::reset(QwtPlot *plot) const { if ( d_data->cache == 0 ) return; const bool doAutoReplot = plot->autoReplot(); plot->setAutoReplot(false); const PrivateData::Cache &cache = *d_data->cache; if ( plot->titleLabel() ) { QwtTextLabel* title = plot->titleLabel(); if ( title->text().testPaintAttribute(QwtText::PaintUsingTextFont) ) { QwtText text = title->text(); text.setColor(cache.titleColor); title->setText(text); } else { QPalette palette = title->palette(); palette.setColor( QPalette::Active, Palette::Text, cache.titleColor); title->setPalette(palette); } if ( title->text().testPaintAttribute(QwtText::PaintUsingTextFont) ) { QwtText text = title->text(); text.setFont(cache.titleFont); title->setText(text); } else { title->setFont(cache.titleFont); } } if ( plot->legend() ) { #if QT_VERSION < 0x040000 QValueList<QWidget *> list = plot->legend()->legendItems(); for ( QValueListIterator<QWidget *> it = list.begin(); it != list.end(); ++it ) #else QList<QWidget *> list = plot->legend()->legendItems(); for ( QList<QWidget*>::iterator it = list.begin(); it != list.end(); ++it ) #endif { QWidget *w = *it; if ( cache.legendFonts.contains(w) ) w->setFont(cache.legendFonts[w]); if ( w->inherits("QwtLegendItem") ) { QwtLegendItem *label = (QwtLegendItem *)w; const QwtPlotItem *plotItem = (const QwtPlotItem*)plot->legend()->find(label); QwtSymbol symbol = label->symbol(); if ( cache.curveSymbolPenColors.contains(plotItem) ) { QPen pen = symbol.pen(); pen.setColor(cache.curveSymbolPenColors[plotItem]); symbol.setPen(pen); } if ( cache.curveSymbolBrushColors.contains(plotItem) ) { QBrush brush = symbol.brush(); brush.setColor(cache.curveSymbolBrushColors[plotItem]); symbol.setBrush(brush); } label->setSymbol(symbol); if ( cache.curveColors.contains(plotItem) ) { QPen pen = label->curvePen(); pen.setColor(cache.curveColors[plotItem]); label->setCurvePen(pen); } } } } for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { QwtScaleWidget *scaleWidget = plot->axisWidget(axis); if ( scaleWidget ) { QPalette palette = scaleWidget->palette(); palette.setColor(QPalette::Active, Palette::Foreground, cache.scaleColor[axis]); scaleWidget->setPalette(palette); scaleWidget->setFont(cache.scaleFont[axis]); scaleWidget->setTitle(cache.scaleTitle[axis]); int startDist, endDist; scaleWidget->getBorderDistHint(startDist, endDist); scaleWidget->setBorderDist(startDist, endDist); } } if ( hasBackgroundColor(plot) ) { QPalette p = plot->palette(); p.setColor(QPalette::Active, Palette::Background, cache.widgetBackground); plot->setPalette(p); } if ( hasBackgroundColor(plot->canvas()) ) { plot->setCanvasBackground(cache.canvasBackground); } const QwtPlotItemList& itmList = plot->itemList(); for ( QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); ++it ) { reset(*it); } delete d_data->cache; d_data->cache = 0; plot->setAutoReplot(doAutoReplot); }