int Plot::axisLabelFormat(int axis) { if (axisValid(axis)){ ScaleDraw *sd = (ScaleDraw *)axisScaleDraw (axis); return sd->labelNumericFormat(); } return 0; }
/*! Change the number format for the major scale of a selected axis \param axis axis index \param f format \param prec precision */ void Plot::setAxisLabelFormat(int axis, char f, int prec) { if (axisValid(axis)) { ScaleDraw *sd = (ScaleDraw *)axisScaleDraw (axis); sd->setLabelFormat(f, prec); } }
/*! \return the number format for the major scale labels of a specified axis \param axis axis index \retval f format character \retval prec precision */ void Plot::axisLabelFormat(int axis, char &f, int &prec) const { if (axisValid(axis)){ ScaleDraw *sd = (ScaleDraw *)axisScaleDraw (axis); sd->labelFormat(f, prec); } else {//for a bad call we return the default values f = 'g'; prec = 4; } }
int Plot::axisLabelPrecision(int axis) { if (axisValid(axis)) { ScaleDraw *sd = (ScaleDraw *)axisScaleDraw (axis); return sd->labelNumericPrecision(); } //for a bad call we return the default values return 4; }
void Plot::drawItems (QPainter *painter, const QRect &rect, const QwtScaleMap map[axisCnt], const QwtPlotPrintFilter &pfilter) const { painter->save(); painter->setRenderHint(QPainter::Antialiasing); for (int i=0; i<QwtPlot::axisCnt; i++){ if (!axisEnabled(i)) continue; drawBreak(painter, rect, map[i], i); } painter->restore(); for (int i=0; i<QwtPlot::axisCnt; i++){ if (!axisEnabled(i)) continue; ScaleEngine *sc_engine = (ScaleEngine *)axisScaleEngine(i); if (!sc_engine->hasBreak()) continue; QwtScaleMap m = map[i]; int lb = m.transform(sc_engine->axisBreakLeft()); int rb = m.transform(sc_engine->axisBreakRight()); int start = lb, end = rb; if (sc_engine->testAttribute(QwtScaleEngine::Inverted)){ end = lb; start = rb; } QRegion cr(rect); if (i == QwtPlot::xBottom || i == QwtPlot::xTop) painter->setClipRegion(cr.subtracted(QRegion(start, rect.y(), abs(end - start), rect.height())), Qt::IntersectClip); else if (i == QwtPlot::yLeft || i == QwtPlot::yRight) painter->setClipRegion(cr.subtracted(QRegion(rect.x(), end, rect.width(), abs(end - start))), Qt::IntersectClip); } QwtPlot::drawItems(painter, rect, map, pfilter); for (int i=0; i<QwtPlot::axisCnt; i++){ if (!axisEnabled(i)) continue; ScaleDraw *sd = (ScaleDraw *) axisScaleDraw (i); int majorTicksType = sd->majorTicksStyle(); int minorTicksType = sd->minorTicksStyle(); bool min = (minorTicksType == ScaleDraw::In || minorTicksType == ScaleDraw::Both); bool maj = (majorTicksType == ScaleDraw::In || majorTicksType == ScaleDraw::Both); if (min || maj) drawInwardTicks(painter, rect, map[i], i, min, maj); } }
QValueList <int> Plot::getMinorTicksType() { QValueList <int> minorTicksType; for (int axis=0; axis<QwtPlot::axisCnt; axis++) { if (axisEnabled(axis)) { ScaleDraw *sd = (ScaleDraw *) axisScaleDraw (axis); minorTicksType << sd->minorTicksStyle(); } else minorTicksType << ScaleDraw::Out; } return minorTicksType; }
void Plot::drawItems (QPainter *painter, const QRect &rect, const QwtArray< QwtScaleMap > &map, const QwtPlotPrintFilter &pfilter) const { QwtPlot::drawItems(painter, rect, map, pfilter); for (int i=0; i<QwtPlot::axisCnt; i++) { if (!axisEnabled(i)) continue; ScaleDraw *sd = (ScaleDraw *) axisScaleDraw (i); int majorTicksType = sd->majorTicksStyle(); int minorTicksType = sd->minorTicksStyle(); bool min = (minorTicksType == ScaleDraw::In || minorTicksType == ScaleDraw::Both); bool maj = (majorTicksType == ScaleDraw::In || majorTicksType == ScaleDraw::Both); if (min || maj) drawInwardTicks(painter, rect, map[i], i, min, maj); } }
int Plot::axisLabelFormat(int axis) { if (axisValid(axis)) { int prec; char format; ScaleDraw *sd = (ScaleDraw *)axisScaleDraw (axis); sd->labelFormat(format, prec); if (format == 'g') return Automatic; else if (format == 'e') return Scientific; else if (format == 'f') return Decimal; else return Superscripts; } return 0; }
void DataCurve::loadData() { Plot *plot = static_cast<Plot *>(this->plot()); Graph *g = static_cast<Graph *>(plot->parent()); if (!g) return; int xcol = d_table->colIndex(d_x_column); int ycol = d_table->colIndex(title().text()); if (xcol < 0 || ycol < 0) { remove(); return; } int r = abs(d_end_row - d_start_row) + 1; QVarLengthArray<double> X(r), Y(r); int xColType = d_table->columnType(xcol); int yColType = d_table->columnType(ycol); QStringList xLabels, yLabels; // store text labels // int xAxis = QwtPlot::xBottom; // if (d_type == GraphOptions::HorizontalBars) // xAxis = QwtPlot::yLeft; QTime time0; QDateTime date0; QString date_time_fmt = d_table->columnFormat(xcol); if (xColType == Table::Time) { for (int i = d_start_row; i <= d_end_row; i++) { QString xval = d_table->text(i, xcol); if (!xval.isEmpty()) { time0 = QTime::fromString(xval, date_time_fmt); if (time0.isValid()) break; } } } else if (xColType == Table::Date) { for (int i = d_start_row; i <= d_end_row; i++) { QString xval = d_table->text(i, xcol); if (!xval.isEmpty()) { date0 = QDateTime::fromString(xval, date_time_fmt); if (date0.isValid()) break; } } } int size = 0; for (int i = d_start_row; i <= d_end_row; i++) { QString xval = d_table->text(i, xcol); QString yval = d_table->text(i, ycol); if (!xval.isEmpty() && !yval.isEmpty()) { bool valid_data = true; if (xColType == Table::Text) { xLabels << xval; X[size] = (double)(size + 1); } else if (xColType == Table::Time) { QTime time = QTime::fromString(xval, date_time_fmt); if (time.isValid()) X[size] = time0.msecsTo(time); } else if (xColType == Table::Date) { QDateTime d = QDateTime::fromString(xval, date_time_fmt); if (d.isValid()) X[size] = (double)date0.secsTo(d); } else X[size] = plot->locale().toDouble(xval, &valid_data); if (yColType == Table::Text) { yLabels << yval; Y[size] = (double)(size + 1); } else Y[size] = plot->locale().toDouble(yval, &valid_data); if (valid_data) size++; } } X.resize(size); Y.resize(size); // The code for calculating the waterfall offsets, that is here in QtiPlot, // has been moved up to // PlotCurve so that MantidCurve can access it as well. if (g->isWaterfallPlot()) { // Calculate the offsets double a, b; computeWaterfallOffsets(a, b); } // End re-jigged waterfall offset code if (!size) { remove(); return; } else { if (d_type == GraphOptions::HorizontalBars) { setData(Y.data(), X.data(), size); foreach (DataCurve *c, d_error_bars) c->setData(Y.data(), X.data(), size); } else { setData(X.data(), Y.data(), size); foreach (DataCurve *c, d_error_bars) c->setData(X.data(), Y.data(), size); } if (xColType == Table::Text) { if (d_type == GraphOptions::HorizontalBars) g->setLabelsTextFormat(QwtPlot::yLeft, ScaleDraw::Text, d_x_column, xLabels); else g->setLabelsTextFormat(QwtPlot::xBottom, ScaleDraw::Text, d_x_column, xLabels); } else if (xColType == Table::Time || xColType == Table::Date) { int axis = QwtPlot::xBottom; if (d_type == GraphOptions::HorizontalBars) axis = QwtPlot::yLeft; ScaleDraw *old_sd = static_cast<ScaleDraw *>(plot->axisScaleDraw(axis)); ScaleDraw *sd = new ScaleDraw(plot, old_sd); if (xColType == Table::Date) sd->setDateTimeOrigin(date0); else sd->setDateTimeOrigin(QDateTime(QDate::currentDate(), time0)); plot->setAxisScaleDraw(axis, sd); } if (yColType == Table::Text) g->setLabelsTextFormat(QwtPlot::yLeft, ScaleDraw::Text, title().text(), yLabels); } if (!d_labels_list.isEmpty()) { (static_cast<Graph *>(plot->parent()))->updatePlot(); loadLabels(); } }
void Plot::setMinorTicksType(int axis, int type) { ScaleDraw *sd = (ScaleDraw *)axisScaleDraw (axis); if (sd) sd->setMinorTicksStyle((ScaleDraw::TicksStyle)type); }
Plot::Plot(QWidget *parent, const char *name) : QwtPlot(parent) { marker_key = 0; curve_key = 0; minTickLength = 5; majTickLength = 9; movedGraph=FALSE; graphToResize=FALSE; ShiftButton=FALSE; setGeometry(QRect(0,0,500,400)); setAxisTitle(QwtPlot::yLeft, tr("Y Axis Title")); setAxisTitle(QwtPlot::xBottom, tr("X Axis Title")); // grid d_grid = new Grid; d_grid->enableX(false); d_grid->enableY(false); d_grid->setMajPen(QPen(Qt::blue, 0, Qt::SolidLine)); d_grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); d_grid->attach(this); //custom scale for (int i= 0; i<QwtPlot::axisCnt; i++) { QwtScaleWidget *scale = (QwtScaleWidget *) axisWidget(i); if (scale) { scale->setMargin(0); //the axis title color must be initialized QwtText title = scale->title(); title.setColor(Qt::black); scale->setTitle(title); ScaleDraw *sd = new ScaleDraw(); sd->setTickLength (QwtScaleDiv::MinorTick, minTickLength); sd->setTickLength (QwtScaleDiv::MediumTick, minTickLength); sd->setTickLength (QwtScaleDiv::MajorTick, majTickLength); setAxisScaleDraw (i, sd); } } QwtPlotLayout *pLayout=plotLayout(); pLayout->setCanvasMargin(0); QwtPlotCanvas* plCanvas = canvas(); plCanvas->setFocusPolicy(QWidget::StrongFocus); plCanvas->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicator); plCanvas->setFocus(); plCanvas->setFrameShadow(QwtPlot::Plain); plCanvas->setCursor(Qt::arrowCursor); plCanvas->setLineWidth(0); setFocusPolicy(QWidget::StrongFocus); setFocusProxy(plCanvas); setFrameShape (QFrame::Box); setLineWidth(0); }
/** Applies this axis' parameters to the graph * */ void ScaleDetails::apply() { if (m_modified && valid()) { // as the classes are separate now this may cause a problem as ideally i'd // get this from the axis tab, // but at the moment there's nothing to cause a problem as the only other // cases that are used are Date // and Time and Mantid doesn't support them in data yet i've been told ScaleDraw::ScaleType type = m_graph->axisType(m_mappedaxis); double start = 0.0, end = 0.0, step = 0.0, breakLeft = -DBL_MAX, breakRight = DBL_MAX; if (type == ScaleDraw::Date) { ScaleDraw *sclDraw = dynamic_cast<ScaleDraw *>( m_graph->plotWidget()->axisScaleDraw(m_mappedaxis)); QDateTime origin = sclDraw->dateTimeOrigin(); start = (double)origin.secsTo(m_dteStartDateTime->dateTime()); end = (double)origin.secsTo(m_dteEndDateTime->dateTime()); } else if (type == ScaleDraw::Time) { ScaleDraw *sclDraw = dynamic_cast<ScaleDraw *>( m_graph->plotWidget()->axisScaleDraw(m_mappedaxis)); QTime origin = sclDraw->dateTimeOrigin().time(); start = (double)origin.msecsTo(m_timStartTime->time()); end = (double)origin.msecsTo(m_timEndTime->time()); } else { start = m_dspnStart->value(); end = m_dspnEnd->value(); } if (m_radStep->isChecked()) { step = m_dspnStep->value(); if (type == ScaleDraw::Time) { switch (m_cmbUnit->currentIndex()) { case 0: break; case 1: step *= 1e3; break; case 2: step *= 6e4; break; case 3: step *= 36e5; break; } } else if (type == ScaleDraw::Date) { switch (m_cmbUnit->currentIndex()) { case 0: step *= 86400; break; case 1: step *= 604800; break; } } } if (m_grpAxesBreaks->isChecked()) { breakLeft = qMin(m_dspnBreakStart->value(), m_dspnBreakEnd->value()); breakRight = qMax(m_dspnBreakStart->value(), m_dspnBreakEnd->value()); } m_graph->setScale( m_mappedaxis, start, end, step, m_spnMajorValue->value(), m_cmbMinorValue->currentText().toInt(), m_cmbScaleType->currentIndex(), m_chkInvert->isChecked(), breakLeft, breakRight, m_spnBreakPosition->value(), m_dspnStepBeforeBreak->value(), m_dspnStepAfterBreak->value(), m_cmbMinorTicksBeforeBreak->currentText().toInt(), m_cmbMinorTicksAfterBreak->currentText().toInt(), m_chkLog10AfterBreak->isChecked(), m_spnBreakWidth->value(), m_chkBreakDecoration->isChecked(), m_dspnN->value()); m_graph->changeIntensity(true); m_graph->notifyChanges(); m_modified = false; } }
/** Initialisation method. Sets up all widgets and variables not done in the * constructor. * */ void ScaleDetails::initWidgets() { if (m_initialised) { return; } else { Plot *d_plot = m_graph->plotWidget(); const QwtScaleDiv *scDiv = d_plot->axisScaleDiv(m_mappedaxis); double start = qMin(scDiv->lBound(), scDiv->hBound()); double end = qMax(scDiv->lBound(), scDiv->hBound()); ScaleDraw::ScaleType type = m_graph->axisType(m_mappedaxis); if (type == ScaleDraw::Date) { ScaleDraw *sclDraw = dynamic_cast<ScaleDraw *>(d_plot->axisScaleDraw(m_mappedaxis)); if (!sclDraw) { throw std::runtime_error("Could not convert the axis Scale Draw object " "to a ScaleDraw object"); } QDateTime origin = sclDraw->dateTimeOrigin(); m_dspnStart->hide(); m_timStartTime->hide(); m_dteStartDateTime->show(); m_dteStartDateTime->setDisplayFormat(sclDraw->format()); m_dteStartDateTime->setDateTime(origin.addSecs((int)start)); m_dspnEnd->hide(); m_timEndTime->hide(); m_dteEndDateTime->show(); m_dteEndDateTime->setDisplayFormat(sclDraw->format()); m_dteEndDateTime->setDateTime(origin.addSecs((int)end)); m_cmbUnit->show(); m_cmbUnit->addItem(tr("days")); m_cmbUnit->addItem(tr("weeks")); m_dspnStep->setValue(m_graph->axisStep(m_mappedaxis) / 86400.0); m_dspnStep->setSingleStep(1); } else if (type == ScaleDraw::Time) { if (ScaleDraw *sclDraw = dynamic_cast<ScaleDraw *>(d_plot->axisScaleDraw(m_mappedaxis))) { QTime origin = sclDraw->dateTimeOrigin().time(); m_dspnStart->hide(); m_dteStartDateTime->hide(); m_timStartTime->show(); m_timStartTime->setDisplayFormat(sclDraw->format()); m_timStartTime->setTime(origin.addMSecs((int)start)); m_dspnEnd->hide(); m_dteEndDateTime->hide(); m_timEndTime->show(); m_timEndTime->setDisplayFormat(sclDraw->format()); m_timEndTime->setTime(origin.addMSecs((int)end)); m_cmbUnit->show(); m_cmbUnit->addItem(tr("millisec.")); m_cmbUnit->addItem(tr("sec.")); m_cmbUnit->addItem(tr("min.")); m_cmbUnit->addItem(tr("hours")); m_cmbUnit->setCurrentIndex(1); m_dspnStep->setValue(m_graph->axisStep(m_mappedaxis) / 1e3); m_dspnStep->setSingleStep(1000); } } else { m_dspnStart->show(); m_dspnStart->setValue(start); m_timStartTime->hide(); m_dteStartDateTime->hide(); m_dspnEnd->show(); m_dspnEnd->setValue(end); m_timEndTime->hide(); m_dteEndDateTime->hide(); m_dspnStep->setValue(m_graph->axisStep(m_mappedaxis)); m_dspnStep->setSingleStep(0.1); } double range = fabs(scDiv->range()); QwtScaleEngine *qwtsc_engine = d_plot->axisScaleEngine(m_mappedaxis); ScaleEngine *sc_engine = dynamic_cast<ScaleEngine *>(qwtsc_engine); if (sc_engine) { if (sc_engine->axisBreakLeft() > -DBL_MAX) { m_dspnBreakStart->setValue(sc_engine->axisBreakLeft()); } else { m_dspnBreakStart->setValue(start + 0.25 * range); } if (sc_engine->axisBreakRight() < DBL_MAX) { m_dspnBreakEnd->setValue(sc_engine->axisBreakRight()); } else { m_dspnBreakEnd->setValue(start + 0.75 * range); } m_grpAxesBreaks->setChecked(sc_engine->hasBreak()); m_spnBreakPosition->setValue(sc_engine->breakPosition()); m_spnBreakWidth->setValue(sc_engine->breakWidth()); m_dspnStepBeforeBreak->setValue(sc_engine->stepBeforeBreak()); m_dspnStepAfterBreak->setValue(sc_engine->stepAfterBreak()); ScaleTransformation::Type scale_type = sc_engine->type(); m_cmbMinorTicksBeforeBreak->clear(); if (scale_type == ScaleTransformation::Log10) { m_cmbMinorTicksBeforeBreak->addItems({"0", "2", "4", "8"}); } else { m_cmbMinorTicksBeforeBreak->addItems({"0", "1", "4", "9", "14", "19"}); } m_cmbMinorTicksBeforeBreak->setEditText( QString::number(sc_engine->minTicksBeforeBreak())); m_cmbMinorTicksAfterBreak->setEditText( QString::number(sc_engine->minTicksAfterBreak())); m_chkLog10AfterBreak->setChecked(sc_engine->log10ScaleAfterBreak()); m_chkBreakDecoration->setChecked(sc_engine->hasBreakDecoration()); m_chkInvert->setChecked( sc_engine->testAttribute(QwtScaleEngine::Inverted)); m_cmbScaleType->setCurrentIndex(scale_type); m_dspnN->setValue(sc_engine->nthPower()); m_cmbMinorValue->clear(); if (scale_type == ScaleTransformation::Log10) { m_cmbMinorValue->addItems({"0", "2", "4", "8"}); } else { m_cmbMinorValue->addItems({"0", "1", "4", "9", "14", "19"}); } m_cmbMinorValue->setEditText( QString::number(d_plot->axisMaxMinor(m_mappedaxis))); bool isColorMap = m_graph->isColorBarEnabled(m_mappedaxis); m_grpAxesBreaks->setEnabled(!isColorMap); if (isColorMap) { m_grpAxesBreaks->setChecked(false); } } else { m_grpAxesBreaks->setChecked(false); m_grpAxesBreaks->setEnabled(false); } const QwtValueList &lst = scDiv->ticks(QwtScaleDiv::MajorTick); m_spnMajorValue->setValue(lst.count()); checkstep(); checkscaletype(); connect(m_grpAxesBreaks, SIGNAL(clicked()), this, SLOT(setModified())); connect(m_chkInvert, SIGNAL(clicked()), this, SLOT(setModified())); connect(m_chkLog10AfterBreak, SIGNAL(clicked()), this, SLOT(setModified())); connect(m_chkBreakDecoration, SIGNAL(clicked()), this, SLOT(setModified())); connect(m_radStep, SIGNAL(clicked()), this, SLOT(setModified())); connect(m_radMajor, SIGNAL(clicked()), this, SLOT(setModified())); connect(m_cmbMinorTicksBeforeBreak, SIGNAL(currentIndexChanged(int)), this, SLOT(setModified())); connect(m_cmbMinorTicksAfterBreak, SIGNAL(currentIndexChanged(int)), this, SLOT(setModified())); connect(m_cmbMinorValue, SIGNAL(currentIndexChanged(int)), this, SLOT(setModified())); connect(m_cmbUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(setModified())); connect(m_cmbScaleType, SIGNAL(currentIndexChanged(int)), this, SLOT(setModified())); connect(m_cmbScaleType, SIGNAL(currentIndexChanged(int)), this, SLOT(checkscaletype())); connect(m_dspnEnd, SIGNAL(valueChanged(double)), this, SLOT(setModified())); connect(m_dspnStart, SIGNAL(valueChanged(double)), this, SLOT(setModified())); connect(m_dspnN, SIGNAL(valueChanged(double)), this, SLOT(setModified())); connect(m_dspnStep, SIGNAL(valueChanged(double)), this, SLOT(setModified())); connect(m_dspnBreakStart, SIGNAL(valueChanged(double)), this, SLOT(setModified())); connect(m_dspnStepBeforeBreak, SIGNAL(valueChanged(double)), this, SLOT(setModified())); connect(m_dspnStepAfterBreak, SIGNAL(valueChanged(double)), this, SLOT(setModified())); connect(m_dspnBreakEnd, SIGNAL(valueChanged(double)), this, SLOT(setModified())); connect(m_spnMajorValue, SIGNAL(valueChanged(int)), this, SLOT(setModified())); connect(m_spnBreakPosition, SIGNAL(valueChanged(int)), this, SLOT(setModified())); connect(m_spnBreakWidth, SIGNAL(valueChanged(int)), this, SLOT(setModified())); connect(m_dteStartDateTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(setModified())); connect(m_dteStartDateTime, SIGNAL(dateChanged(QDate)), this, SLOT(setModified())); connect(m_dteStartDateTime, SIGNAL(timeChanged(QTime)), this, SLOT(setModified())); connect(m_dteEndDateTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(setModified())); connect(m_dteEndDateTime, SIGNAL(dateChanged(QDate)), this, SLOT(setModified())); connect(m_dteEndDateTime, SIGNAL(timeChanged(QTime)), this, SLOT(setModified())); connect(m_timStartTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(setModified())); connect(m_timStartTime, SIGNAL(dateChanged(QDate)), this, SLOT(setModified())); connect(m_timStartTime, SIGNAL(timeChanged(QTime)), this, SLOT(setModified())); connect(m_timEndTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(setModified())); connect(m_timEndTime, SIGNAL(dateChanged(QDate)), this, SLOT(setModified())); connect(m_timEndTime, SIGNAL(timeChanged(QTime)), this, SLOT(setModified())); m_initialised = true; } }
Plot::Plot(int width, int height, QWidget *parent, const char *) : QwtPlot(parent) { setAutoReplot (false); marker_key = 0; curve_key = 0; minTickLength = 5; majTickLength = 9; setGeometry(QRect(0, 0, width, height)); setAxisTitle(QwtPlot::yLeft, tr("Y Axis Title")); setAxisTitle(QwtPlot::xBottom, tr("X Axis Title")); //due to the plot layout updates, we must always have a non empty title setAxisTitle(QwtPlot::yRight, tr(" ")); setAxisTitle(QwtPlot::xTop, tr(" ")); // grid d_grid = new Grid(); d_grid->attach(this); //custom scale for (int i= 0; i<QwtPlot::axisCnt; i++) { QwtScaleWidget *scale = (QwtScaleWidget *) axisWidget(i); if (scale) { scale->setMargin(0); //the axis title color must be initialized... QwtText title = scale->title(); title.setColor(Qt::black); scale->setTitle(title); //...same for axis color QPalette pal = scale->palette(); pal.setColor(QPalette::Foreground, QColor(Qt::black)); scale->setPalette(pal); ScaleDraw *sd = new ScaleDraw(this); sd->setTickLength(QwtScaleDiv::MinorTick, minTickLength); sd->setTickLength(QwtScaleDiv::MediumTick, minTickLength); sd->setTickLength(QwtScaleDiv::MajorTick, majTickLength); setAxisScaleDraw (i, sd); setAxisScaleEngine (i, new ScaleEngine()); } } QwtPlotLayout *pLayout = plotLayout(); pLayout->setCanvasMargin(0); pLayout->setAlignCanvasToScales (true); QwtPlotCanvas* plCanvas = canvas(); plCanvas->setFocusPolicy(Qt::StrongFocus); plCanvas->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicator); //plCanvas->setFocus(); plCanvas->setFrameShadow(QwtPlot::Plain); plCanvas->setCursor(Qt::arrowCursor); plCanvas->setLineWidth(0); plCanvas->setPaintAttribute(QwtPlotCanvas::PaintCached, false); plCanvas->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); QColor background = QColor(Qt::white); background.setAlpha(255); QPalette palette; palette.setColor(QPalette::Window, background); setPalette(palette); setCanvasBackground (background); setFocusPolicy(Qt::StrongFocus); //setFocusProxy(plCanvas); setFrameShape(QFrame::Box); setLineWidth(0); }
void DataCurve::loadData() { Graph *g = (Graph *)plot(); if (!g) return; int xcol = d_table->colIndex(d_x_column); int ycol = d_table->colIndex(title().text()); if (xcol < 0 || ycol < 0){ remove(); return; } int r = abs(d_end_row - d_start_row) + 1; QVarLengthArray<double> X(r), Y(r); int xColType = d_table->columnType(xcol); int yColType = d_table->columnType(ycol); QStringList xLabels, yLabels;// store text labels QTime time0; QDateTime date0; QString date_time_fmt = d_table->columnFormat(xcol); if (xColType == Table::Time){ for (int i = d_start_row; i <= d_end_row; i++ ){ QString xval=d_table->text(i,xcol); if (!xval.isEmpty()){ time0 = QTime::fromString (xval, date_time_fmt); if (time0.isValid()) break; } } } else if (xColType == Table::Date){ for (int i = d_start_row; i <= d_end_row; i++ ){ QString xval=d_table->text(i,xcol); if (!xval.isEmpty()){ date0 = QDateTime::fromString (xval, date_time_fmt); if (date0.isValid()) break; } } } int size = 0; for (int i = d_start_row; i <= d_end_row; i++ ){ QString xval = d_table->text(i,xcol); QString yval = d_table->text(i,ycol); if (!xval.isEmpty() && !yval.isEmpty()){ bool valid_data = true; if (xColType == Table::Text){ xLabels << xval; X[size] = (double)(size + 1); } else if (xColType == Table::Time){ QTime time = QTime::fromString (xval, date_time_fmt); if (time.isValid()) X[size]= time0.msecsTo (time); } else if (xColType == Table::Date){ QDateTime d = QDateTime::fromString (xval, date_time_fmt); if (d.isValid()) X[size] = (double) date0.secsTo(d); } else X[size] = g->locale().toDouble(xval, &valid_data); if (yColType == Table::Text){ yLabels << yval; Y[size] = (double)(size + 1); } else Y[size] = g->locale().toDouble(yval, &valid_data); if (valid_data) size++; } } X.resize(size); Y.resize(size); if (!size){ remove(); return; } else { if (d_type == Graph::HorizontalBars){ setData(Y.data(), X.data(), size); foreach(DataCurve *c, d_error_bars) c->setData(Y.data(), X.data(), size); } else { setData(X.data(), Y.data(), size); foreach(DataCurve *c, d_error_bars) c->setData(X.data(), Y.data(), size); } if (xColType == Table::Text){ if (d_type == Graph::HorizontalBars) g->setLabelsTextFormat(QwtPlot::yLeft, ScaleDraw::Text, d_x_column, xLabels); else g->setLabelsTextFormat(QwtPlot::xBottom, ScaleDraw::Text, d_x_column, xLabels); } else if (xColType == Table::Time || xColType == Table::Date){ int axis = QwtPlot::xBottom; if (d_type == Graph::HorizontalBars) axis = QwtPlot::yLeft; ScaleDraw *old_sd = (ScaleDraw *)g->axisScaleDraw(axis); ScaleDraw *sd = new ScaleDraw(g, old_sd); if (xColType == Table::Date) sd->setDateTimeOrigin(date0); else sd->setDateTimeOrigin(QDateTime(QDate::currentDate(), time0)); g->setAxisScaleDraw(axis, sd); } if (yColType == Table::Text) g->setLabelsTextFormat(QwtPlot::yLeft, ScaleDraw::Text, title().text(), yLabels); } if (!d_labels_list.isEmpty()){ ((Graph*)plot())->updatePlot(); loadLabels(); } }
void FFT::outputGraphs() { createOutputGraph(); MultiLayer *ml = d_output_graph->multiLayer(); d_output_graph->setTitle(QString::null); d_output_graph->setYAxisTitle(tr("Angle (deg)")); d_output_graph->enableAxis(QwtPlot::xTop, true); d_output_graph->enableAxis(QwtPlot::yRight, true); if (!d_inverse) d_output_graph->setAxisTitle(QwtPlot::xTop, tr("Frequency") + " (" + tr("Hz") + ")"); else d_output_graph->setAxisTitle(QwtPlot::xTop, tr("Time") + + " (" + tr("s") + ")"); ScaleDraw *sd = (ScaleDraw *)d_output_graph->axisScaleDraw(QwtPlot::yLeft); if (sd) sd->setShowTicksPolicy(ScaleDraw::HideBegin); sd = (ScaleDraw *)d_output_graph->axisScaleDraw(QwtPlot::yRight); if (sd) sd->setShowTicksPolicy(ScaleDraw::HideBegin); sd = (ScaleDraw *)d_output_graph->axisScaleDraw(QwtPlot::xBottom); if (sd){ sd->setShowTicksPolicy(ScaleDraw::HideBeginEnd); sd->enableComponent(QwtAbstractScaleDraw::Backbone, false); } QString tableName = d_result_table->objectName(); PlotCurve *pc = d_output_graph->insertCurve(d_result_table, 0, tableName + "_" + tr("Angle"), 0); pc->setPen(QPen(d_curveColor, 1)); d_output_graph->removeLegend(); d_output_graph->updatePlot(); Graph *g = ml->addLayer(0, 0, 0, 0, true); g->setTitle(QString::null); if (!d_inverse) g->setXAxisTitle(tr("Frequency") + " (" + tr("Hz") + ")"); else g->setXAxisTitle(tr("Time") + + " (" + tr("s") + ")"); g->setYAxisTitle(tr("Amplitude")); g->removeLegend(); sd = (ScaleDraw *)g->axisScaleDraw(QwtPlot::xTop); if (sd) sd->setShowTicksPolicy(ScaleDraw::HideBeginEnd); PlotCurve *c = g->insertCurve(d_result_table, 0, tableName + "_" + tr("Amplitude"), 0); c->setPen(QPen(d_curveColor, 1)); g->updatePlot(); double rb = g->axisScaleDiv(QwtPlot::xBottom)->upperBound(); d_output_graph->setAxisScale(QwtPlot::xBottom, 0, rb); d_output_graph->setAxisScale(QwtPlot::xTop, 0, rb); g->setAxisScale(QwtPlot::xBottom, 0, rb); g->setAxisScale(QwtPlot::xTop, 0, rb); ml->setAlignPolicy(MultiLayer::AlignCanvases); ml->setRows(2); ml->setCols(1); ml->setSpacing(0, 0); ml->linkXLayerAxes(); ml->setCommonLayerAxes(false, true); ml->arrangeLayers(false, false); }