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 specCanvasItem::setSymbolStyle(const int& newStyle) { if(oldSymbol) { if(specPlotStyle::noSymbol == newStyle) { delete oldSymbol ; oldSymbol = 0 ; } else oldSymbol->setStyle(QwtSymbol::Style(newStyle)) ; } else { if(specPlotStyle::noSymbol == newStyle) setSymbol(0) ; else { QwtSymbol* newSymbol = symbol() ? cloneSymbol(symbol()) : (new QwtSymbol) ; newSymbol->setStyle(QwtSymbol::Style(newStyle)) ; setSymbol(newSymbol) ; } } }
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()); } }
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()); }
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(); }
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 SymbolBox::init() { QPixmap icon = QPixmap(14, 14); icon.fill ( QColor (gray) ); const QRect r= QRect(0, 0, 14, 14); QPainter p(&icon); p.setBackgroundColor(QColor(gray)); QwtSymbol symb; p.setBrush(QBrush(QColor(white))); this->insertItem(tr("No Symbol" )); symb.setStyle (QwtSymbol::Ellipse); symb.draw(&p, r); this->insertItem(icon, tr("Ellipse" )); symb.setStyle (QwtSymbol::Rect); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Rectangle")); symb.setStyle (QwtSymbol::Diamond); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Diamond")); symb.setStyle (QwtSymbol::Triangle); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Triangle")); symb.setStyle (QwtSymbol::DTriangle); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Down Triangle")); symb.setStyle (QwtSymbol::UTriangle); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Up Triangle")); symb.setStyle (QwtSymbol::LTriangle); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Left Triangle")); symb.setStyle (QwtSymbol::RTriangle); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Right Triangle")); symb.setStyle (QwtSymbol::Cross); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Cross")); symb.setStyle (QwtSymbol::XCross); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Diagonal Cross")); symb.setStyle (QwtSymbol::HLine); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Horizontal Line")); symb.setStyle (QwtSymbol::VLine); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Vertical Line")); symb.setStyle (QwtSymbol::Star1); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Star 1")); symb.setStyle (QwtSymbol::Star2); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Star 2")); symb.setStyle (QwtSymbol::Hexagon); p.eraseRect ( r ); symb.draw(&p, r); this->insertItem(icon,tr("Hexagon")); p.end(); }
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); }
MainWin::MainWin() { int i; xMap.setScaleInterval(-0.5, 10.5); yMap.setScaleInterval(-1.1, 1.1); // // Frame style // setFrameStyle(QFrame::Box|QFrame::Raised); setLineWidth(2); setMidLineWidth(3); // // Calculate values // for(i=0; i<Size;i++) { xval[i] = double(i) * 10.0 / double(Size - 1); yval[i] = sin(xval[i]) * cos(2.0 * xval[i]); } // // define curve styles // QwtSymbol sym; i = 0; sym.setStyle(QwtSymbol::Cross); sym.setPen(QColor(Qt::black)); sym.setSize(5); crv[i].setSymbol(sym); crv[i].setPen(QColor(Qt::darkGreen)); crv[i].setStyle(QwtPlotCurve::Lines); crv[i].setCurveAttribute(QwtPlotCurve::Fitted); i++; sym.setStyle(QwtSymbol::Ellipse); sym.setPen(QColor(Qt::blue)); sym.setBrush(QColor(Qt::yellow)); sym.setSize(5); crv[i].setSymbol(sym); crv[i].setPen(QColor(Qt::red)); crv[i].setStyle(QwtPlotCurve::Sticks); i++; crv[i].setPen(QColor(Qt::darkBlue)); crv[i].setStyle(QwtPlotCurve::Lines); i++; #if QT_VERSION >= 0x040000 crv[i].setPen(QColor(Qt::darkBlue)); crv[i].setStyle(QwtPlotCurve::Lines); crv[i].setRenderHint(QwtPlotItem::RenderAntialiased); i++; #endif crv[i].setPen(QColor(Qt::darkCyan)); crv[i].setStyle(QwtPlotCurve::Steps); i++; sym.setStyle(QwtSymbol::XCross); sym.setPen(QColor(Qt::darkMagenta)); crv[i].setSymbol(sym); crv[i].setStyle(QwtPlotCurve::NoCurve); i++; // // attach data // for(i=0;i<CurvCnt;i++) crv[i].setRawData(xval,yval,Size); }
Variog_plot:: Variog_plot( const Discrete_function& df, const Variogram_function_adaptor<Covariance<GsTLPoint> > *model, GsTLVector<double> angle, const std::vector<int>& pairs, const QString& title, bool y_starts_at_zero, QWidget *parent, const char *name) : QwtPlot(parent), pairs_shown_(false), model1_(0), model2_(0) { //this->setWindowFlags( ); setWindowFlags(Qt::SubWindow | Qt::MSWindowsFixedSizeDialogHint); if (name) setObjectName(name); setWindowIcon(QIcon()); //------------ // 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); 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 t("distance"); t.setFont(axis_font); this->setAxisTitle( QwtPlot::xBottom,t); //------------- if( !title.isEmpty() ) { QFont title_font; QwtText T(title); title_font.setPointSize( 8 ); T.setFont(title_font); this->setTitle( T ); this->setWindowTitle( title ); } std::vector<double> x_vals = df.x_values(); std::vector<double> y_vals = df.y_values(); angle_ = angle; 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.no_data_value(), 0.001 ) || GsTL::equals( y_vals[i], df.no_data_value(), 0.001 ) ) continue; x[actual_size] = x_vals[i]; y[actual_size] = y_vals[i]; pairs_.push_back( pairs[i] ); pairs_coord_x_.push_back( x_vals[i] ); pairs_coord_y_.push_back( y_vals[i] ); actual_size++; } model1_=model; const float ymargin = 1.05; const float xmargin = 1.06; if( actual_size > 0 ) { float ymax = *(std::max_element( y, y+actual_size )); float ymin = *(std::min_element( y, y+actual_size )); if( ymax == 0 && ymin == 0 ) this->setAxisAutoScale( QwtPlot::yLeft ); else if(ymax>0) this->setAxisScale( QwtPlot::yLeft, 0.0, ymax*ymargin ); else this->setAxisScale( QwtPlot::yLeft, ymin*(2-ymargin), ymax*ymargin ); if( y_starts_at_zero ) this->setAxisScale( QwtPlot::yLeft, 0.0, ymax*ymargin ); float xmax = *(std::max_element( x, x+actual_size )); this->setAxisScale( QwtPlot::xBottom, 0, xmax*xmargin ); } curve1_= new QwtPlotCurve("Discrete Function"); curve1_->setData( x, y, actual_size ); curve2_=new QwtPlotCurve("Model"); curve1_->attach(this); curve2_->attach(this); QwtSymbol symbol; symbol.setStyle(QwtSymbol::XCross); symbol.setPen( QPen(Qt::red, 3 ) ); symbol.setSize(7); curve1_->setSymbol(symbol); curve1_->setStyle(QwtPlotCurve::NoCurve); symbol.setStyle( QwtSymbol::NoSymbol ); symbol.setPen( QPen( Qt::blue, 1 ) ); curve2_->setSymbol(symbol); curve2_->setStyle(QwtPlotCurve::Lines); this->replot(); max_x_ = this->axisScaleDiv( QwtPlot::xBottom )->hBound(); /* QObject::connect( this, SIGNAL(plotMouseReleased(const QMouseEvent& )), this, SLOT(show_pairs_count(const QMouseEvent&)) ); */ delete [] x; delete [] y; }
void PlotCurve::restoreCurveLayout(const QStringList& lst) { QStringList::const_iterator line = lst.begin(); for (line = lst.begin(); line != lst.end(); line++) { QString s = (*line).stripWhiteSpace(); if (s == "<Pen>") { QPen pen; pen.setCosmetic(true); while(s != "</Pen>") { s = (*(++line)).stripWhiteSpace(); if (s.contains("<Color>")) pen.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Alpha>")) { QColor c = pen.color(); c.setAlpha(s.remove("<Alpha>").remove("</Alpha>").toInt()); pen.setColor(c); } 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)).stripWhiteSpace(); if (s.contains("<Color>")) brush.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Alpha>")) { QColor c = brush.color(); c.setAlpha(s.remove("<Alpha>").remove("</Alpha>").toInt()); brush.setColor(c); } 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)).stripWhiteSpace(); 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)).stripWhiteSpace(); if (s.contains("<Color>")) pen.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Alpha>")) { QColor c = pen.color(); c.setAlpha(s.remove("<Alpha>").remove("</Alpha>").toInt()); pen.setColor(c); } 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()); } pen.setCosmetic(true); symbol.setPen(pen); } else if (s == "<SymbolBrush>") { QBrush brush; while(s != "</SymbolBrush>") { s = (*(++line)).stripWhiteSpace(); if (s.contains("<Color>")) brush.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Alpha>")) { QColor c = brush.color(); c.setAlpha(s.remove("<Alpha>").remove("</Alpha>").toInt()); brush.setColor(c); } 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("<CurveType>")) setCurveType((QwtPlotCurve::CurveType)s.remove("<CurveType>").remove("</CurveType>").toInt()); else if (s.contains("<Visible>")) setVisible(s.remove("<Visible>").remove("</Visible>").toInt()); } }
void PfPvPlot::setData(RideItem *_rideItem) { // 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(); rideItem = _rideItem; RideFile *ride = rideItem->ride(); if (ride) { // quickly erase old data curve->setVisible(false); // due to the discrete power and cadence values returned by the // power meter, there will very likely be many duplicate values. // Rather than pass them all to the curve, use a set to strip // out duplicates. std::set<std::pair<double, double> > dataSet; std::set<std::pair<double, double> > dataSetSelected; long tot_cad = 0; long tot_cad_points = 0; foreach(const RideFilePoint *p1, ride->dataPoints()) { if (p1->watts != 0 && p1->cad != 0) { double aepf = (p1->watts * 60.0) / (p1->cad * cl_ * 2.0 * PI); double cpv = (p1->cad * cl_ * 2.0 * PI) / 60.0; if (aepf <= 2500) { // > 2500 newtons is our out of bounds dataSet.insert(std::make_pair<double, double>(aepf, cpv)); tot_cad += p1->cad; tot_cad_points++; } } } setCAD(tot_cad_points ? tot_cad / tot_cad_points : 0); if (tot_cad_points == 0) { //setTitle(tr("no cadence")); refreshZoneItems(); curve->setVisible(false); } else { // Now that we have the set of points, transform them into the // QwtArrays needed to set the curve's data. QwtArray<double> aepfArray; QwtArray<double> cpvArray; std::set<std::pair<double, double> >::const_iterator j(dataSet.begin()); while (j != dataSet.end()) { const std::pair<double, double>& dataPoint = *j; aepfArray.push_back(dataPoint.first); cpvArray.push_back(dataPoint.second); ++j; } curve->setData(cpvArray, aepfArray); QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setSize(6); sym.setBrush(QBrush(Qt::NoBrush)); // now show the data (zone shading would already be visible) refreshZoneItems(); curve->setVisible(true); } } else {
void SymbolBox::init(bool showNoSymbol) { QPixmap icon = QPixmap(15, 15); QColor c = QColor(Qt::gray); icon.fill(c); const QRect r = QRect(1, 1, 14, 14); QPainter p(&icon); p.setRenderHint(QPainter::Antialiasing); QwtSymbol symb; p.setBrush(QBrush(QColor(Qt::white))); if (showNoSymbol) this->addItem(tr("No Symbol")); symb.setStyle(QwtSymbol::Ellipse); symb.draw(&p, r); this->addItem(icon, tr("Ellipse")); symb.setStyle(QwtSymbol::Rect); icon.fill(c); symb.draw(&p, r.adjusted(0, 0, -1, -1)); this->addItem(icon, tr("Rectangle")); symb.setStyle(QwtSymbol::Diamond); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Diamond")); symb.setStyle(QwtSymbol::Triangle); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Triangle")); symb.setStyle(QwtSymbol::DTriangle); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Down Triangle")); symb.setStyle(QwtSymbol::UTriangle); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Up Triangle")); symb.setStyle(QwtSymbol::LTriangle); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Left Triangle")); symb.setStyle(QwtSymbol::RTriangle); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Right Triangle")); symb.setStyle(QwtSymbol::Cross); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Cross")); symb.setStyle(QwtSymbol::XCross); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Diagonal Cross")); symb.setStyle(QwtSymbol::HLine); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Horizontal Line")); symb.setStyle(QwtSymbol::VLine); p.eraseRect(r); symb.draw(&p, r); this->addItem(icon, tr("Vertical Line")); symb.setStyle(QwtSymbol::Star1); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Star 1")); symb.setStyle(QwtSymbol::Star2); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Star 2")); symb.setStyle(QwtSymbol::Hexagon); icon.fill(c); symb.draw(&p, r); this->addItem(icon, tr("Hexagon")); p.end(); }