void CurvesDialog::showCurveBtn(int)
{
	QwtPlotItem *it = d_graph->plotItem(contents->currentRow());
	if (!it)
		return;

    if (it->rtti() == QwtPlotItem::Rtti_PlotSpectrogram)
    {
        btnEditFunction->setEnabled(false);
        btnAssociations->setEnabled(false);
        btnRange->setEnabled(false);
        return;
    }

    PlotCurve *c = (PlotCurve *)it;
	if (c->type() == Graph::Function)
	{
		btnEditFunction->setEnabled(true);
		btnAssociations->setEnabled(false);
		btnRange->setEnabled(false);
		return;
	}

    btnAssociations->setEnabled(true);

    btnRange->setEnabled(true);
	if (c->type() == Graph::ErrorBars)
  		btnRange->setEnabled(false);
}
Beispiel #2
0
void Fit::setDataCurve(int curve, double start, double end) {
  if (!d_graph)
    return;

  if (d_n > 0)
    delete[] d_w;

  Filter::setDataCurve(curve, start, end);

  d_w = new double[d_n];
  PlotCurve *plotCurve = dynamic_cast<PlotCurve *>(d_curve);
  DataCurve *dataCurve = dynamic_cast<DataCurve *>(d_curve);
  // if it is a DataCurve (coming from a Table)
  if (plotCurve && dataCurve && plotCurve->type() != GraphOptions::Function) {
    QList<DataCurve *> lst = dataCurve->errorBarsList();
    foreach (DataCurve *c, lst) {
      QwtErrorPlotCurve *er = dynamic_cast<QwtErrorPlotCurve *>(c);
      if (er && !er->xErrors()) {
        d_weighting = Instrumental;
        for (int i = 0; i < d_n; i++)
          d_w[i] = er->errorValue(i); // d_w are equal to the error bar values
        weighting_dataset = er->title().text();
        return;
      }
    }
QString LegendWidget::parse(const QString& str)
{
    QString s = str;
    s.remove(QRegExp("\\l(*)", Qt::CaseSensitive, QRegExp::Wildcard));
    s.remove(QRegExp("\\p{*}", Qt::CaseSensitive, QRegExp::Wildcard));

	QString aux = str;
    while (aux.contains(QRegExp("%(*)", Qt::CaseInsensitive, QRegExp::Wildcard))){//curve name specification
		int pos = str.indexOf("%(", 0, Qt::CaseInsensitive);
        int pos2 = str.indexOf(")", pos, Qt::CaseInsensitive);
		QString spec = str.mid(pos + 2, pos2 - pos - 2);
		QStringList lst = spec.split(",");
		if (!lst.isEmpty()){
        	int cv = lst[0].toInt() - 1;
        	if (d_plot && cv >= 0 && cv < d_plot->curveCount()){
				PlotCurve *c = (PlotCurve *)d_plot->curve(cv);
            	if (c){
					if (lst.count() == 1)
						s = s.replace(pos, pos2-pos+1, c->title().text());
					else if (lst.count() == 3 && c->type() == Graph::Pie){
						Table *t = ((DataCurve *)c)->table();
						int col = t->colIndex(c->title().text());
						int row = lst[2].toInt() - 1;
						s = s.replace(pos, pos2-pos+1, t->text(row, col));
					}
				}
        	}
			aux = aux.right(aux.length() - pos2 - 1);
		}
    }
    return s;
}
Beispiel #4
0
/**
 * Returns the index of the closest curve to a point on the canvas.
 * Also returns index of the nearest data point on that curve.
 * @param xpos :: x coordinate of a point on the canvas in pixels.
 * @param ypos :: y coordinate of a point on the canvas in pixels.
 * @param dist :: ?
 * @param point :: Output index of the nearest data point to the point with coordinates (xpos,ypos)
 */
int Plot::closestCurve(int xpos, int ypos, int &dist, int &point)
{
	QwtScaleMap map[QwtPlot::axisCnt];
	for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
		map[axis] = canvasMap(axis);

  double dmin = std::numeric_limits<double>::max();
	int key = -1;
	for (QMap<int, QwtPlotItem *>::iterator iter = d_curves.begin(); iter != d_curves.end(); ++iter )
	{
		QwtPlotItem *item = (QwtPlotItem *)iter.data();
		if (!item)
			continue;

    if(item->rtti() != QwtPlotItem::Rtti_PlotSpectrogram)
    {
      PlotCurve *c = (PlotCurve *)item;
      DataCurve *dc = dynamic_cast<DataCurve *>(item);
      if (dc)
      {
        if (c->type() != Graph::Function && dc->hasLabels() &&
          dc->selectedLabels(QPoint(xpos, ypos))){
            dist = 0;
            return iter.key();
        } else
          dc->setLabelsSelected(false);
      }

      for (int i=0; i<c->dataSize(); i++)
      {
        double cx = map[c->xAxis()].xTransform(c->x(i)) - double(xpos);
        double cy = map[c->yAxis()].xTransform(c->y(i)) - double(ypos);
        double f = qwtSqr(cx) + qwtSqr(cy);
        if (f < dmin && c->type() != Graph::ErrorBars)
        {
          dmin = f;
          key = iter.key();
          point = i;
        }
      }
    }
  }
	dist = static_cast<int>(sqrt(dmin));
	return key;
}
Beispiel #5
0
int LegendWidget::symbolsMaxWidth()
{
  QList<int> cvs = d_plot->curveKeys();
  int curves = cvs.count();
  if (!curves)
    return 0;

  // RJT (22/09/09): For rest of method, copied in code from current 
  // QtiPlot (rev. 1373) to fix infinite loop if closing bracket missing
  int maxL = 0;
  QString text = d_text->text();
  QStringList titles = text.split("\n", QString::KeepEmptyParts);
  for (int i=0; i<(int)titles.count(); i++){
    QString s = titles[i];
    while (s.contains("\\l(",Qt::CaseInsensitive)){
      int pos = s.indexOf("\\l(", 0,Qt::CaseInsensitive);
      int pos1 = s.indexOf("(", pos);
      int pos2 = s.indexOf(")", pos1);
      int pos3 = s.indexOf(",",pos1);
      if (pos3 != -1 && pos3 < pos2 ) pos2=pos3; // for pi charts get dataset number
      if (pos2 == -1){
        s = s.right(s.length() - pos1 - 1);
        continue;
      }

      int point = 0;
      PlotCurve* c = getCurve(s.mid(pos1 + 1, pos2 - pos1 - 1), point);
      if (c && c->type() == Graph::Pie){
        maxL = 2*d_text->font().pointSize();//10;
        line_length = 0;
        s = s.right(s.length() - pos2 - 1);
        continue;
      }

      if (c && c->rtti() != QwtPlotItem::Rtti_PlotSpectrogram) {
        if (c->type() == Graph::Pie ||
          c->type() == Graph::VerticalBars ||
          c->type() == Graph::HorizontalBars ||
          c->type() == Graph::Histogram ||
          c->type() == Graph::Box){
          maxL = 2*d_text->font().pointSize();//10;
          line_length = 0;
        } else {
          int l = c->symbol().size().width();
          if (l < 3)
            l = 3;
          else if (l > 15)
            l = 15;
          if (l>maxL && c->symbol().style() != QwtSymbol::NoSymbol)
            maxL = l;
        }
      }
      s = s.right(s.length() - pos2 - 1);
    }

    if (titles[i].contains("\\p{")){ // old syntax for pie charts
      maxL = 2*d_text->font().pointSize();//10;
      line_length = 0;
    }
  }
  return maxL;
}