コード例 #1
0
bool KstHsDialog::editSingleObject(KstHistogramPtr hsPtr) {
  double new_min;
  double new_max;

  hsPtr->readLock();
  new_min = hsPtr->xMin();
  new_max = hsPtr->xMax();
  hsPtr->unlock();

  if (_minDirty) {
    new_min = _w->Min->text().toDouble();
  }

  if (_maxDirty) {
    new_max = _w->Max->text().toDouble();
  }

  if (new_max < new_min) {
    double m = new_max;

    new_max = new_min;
    new_min = m;
  }

  if (new_max == new_min) {
    QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("Max and Min can not be equal."));
    _w->Min->setFocus();
    return false;
  }

  int new_n_bins = _w->N->text().toInt();
  if (_nDirty && new_n_bins < 1) {
    QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("You must have one or more bins in a histogram."));
    _w->N->setFocus();
    return false;
  }

  if (_vectorDirty) {
    KST::vectorList.lock().readLock();
    hsPtr->setVector(*KST::vectorList.findTag(_w->_vector->selectedVector()));
    KST::vectorList.lock().unlock();
  }

  hsPtr->writeLock();

  if (_nDirty) {
    hsPtr->setNBins(new_n_bins);
  }

  if (_minDirty || _maxDirty) {
    hsPtr->setXRange(new_min, new_max);
  }

  if (_realTimeAutoBinDirty) {
    hsPtr->setRealTimeAutoBin(_w->_realTimeAutoBin->isChecked());
  }

  if (_normIsPercentDirty || _normIsFractionDirty || _peakIs1Dirty || _normIsNumberDirty) {
    if (_w->NormIsPercent->isChecked()) {
      hsPtr->setIsNormPercent();
    } else if (_w->NormIsFraction->isChecked()) {
      hsPtr->setIsNormFraction();
    } else if (_w->PeakIs1->isChecked()) {
      hsPtr->setIsNormOne();
    } else {
      hsPtr->setIsNormNum();
    }
  }

  hsPtr->setRecursed(false);
  if (hsPtr->recursion()) {
    hsPtr->setRecursed(true);
    hsPtr->unlock();
    QMessageBox::critical(this, QObject::tr("Kst"), QObject::tr("There is a recursion resulting from the histogram you entered."));
    return false;
  }

  hsPtr->setDirty();
  hsPtr->unlock();

  return true;
}
コード例 #2
0
bool KstHsDialog::newObject() {
  QString tag_name = _tagName->text();

  if (tag_name == defaultTag) {
    tag_name = KST::suggestHistogramName(KstObjectTag::fromString(_w->_vector->selectedVector()));
  }

  //
  // verify that the curve name is unique...
  //

  if (KstData::self()->dataTagNameNotUnique(tag_name)) {
    _tagName->setFocus();
    return false;
  }

  if (_w->_vector->selectedVector().isEmpty()) {
    QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("New Histogram not made: define vectors first."));
    return false;
  }

  //
  // find max and min...
  //

  double new_min = _w->Min->text().toDouble();
  double new_max = _w->Max->text().toDouble();

  if (new_max < new_min) {
    double m = new_max;

    new_max = new_min;
    new_min = m;
  }

  if (new_max == new_min) {
    QMessageBox::warning(this, QObject::tr("kst"), QObject::tr("Max and Min can not be equal."));
    return false;
  }

  int new_n_bins = _w->N->text().toInt();
  if (new_n_bins < 1) {
    QMessageBox::warning(this, QObject::tr("kst"), QObject::tr("You must have one or more bins in a histogram."));
    return false;
  }

  KstHsNormType new_norm_mode;
  if (_w->NormIsPercent->isChecked()) {
    new_norm_mode = KST_HS_PERCENT;
  } else if (_w->NormIsFraction->isChecked()) {
    new_norm_mode = KST_HS_FRACTION;
  } else if (_w->PeakIs1->isChecked()) {
    new_norm_mode = KST_HS_MAX_ONE;
  } else {
    new_norm_mode = KST_HS_NUMBER;
  }

  KstHistogramPtr hs;

  KST::vectorList.lock().readLock();
  KstVectorPtr vp = *KST::vectorList.findTag(_w->_vector->selectedVector());
  KST::vectorList.lock().unlock();
  if (vp) {
    KstVCurvePtr vc;
    KstViewWindow *w;
    QColor color;

    vp->readLock();
    hs = new KstHistogram(tag_name, vp, new_min, new_max,
                          new_n_bins, new_norm_mode);
    vp->unlock();

    hs->setRealTimeAutoBin(_w->_realTimeAutoBin->isChecked());
  
// xxx    color = KstApp::inst()->chooseColorDlg()->getColorForCurve(hs->vX(), hs->vY());
    if (!color.isValid()) {
      color = _w->_curveAppearance->color();
    }
    vc = new KstVCurve(KST::suggestCurveName(hs->tag(), true), hs->vX(), hs->vY(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), color);
  
    vc->setHasPoints(_w->_curveAppearance->showPoints());
    vc->setHasLines(_w->_curveAppearance->showLines());
    vc->setHasBars(_w->_curveAppearance->showBars());
    vc->setPointStyle(_w->_curveAppearance->pointType());
    vc->setLineWidth(_w->_curveAppearance->lineWidth());
    vc->setLineStyle(_w->_curveAppearance->lineStyle());
    vc->setBarStyle(_w->_curveAppearance->barStyle());
    vc->setPointDensity(_w->_curveAppearance->pointDensity());
  
    QString legendText = _legendText->text();

    if (legendText == defaultTag) {
      vc->setLegendText(QString(""));
    } else {
      vc->setLegendText(legendText);
    }
/* xxx  
    w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText()));
*/
    if (!w) {
      QString n = KstApp::inst()->newWindow(KST::suggestWinName());

// xxx      w = static_cast<KstViewWindow*>(KstApp::inst()->findWindow(n));
    }
    
    if (w) {
      Kst2DPlotPtr plot;
    
      if (_w->_curvePlacement->existingPlot()) {
        plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName()));
        if (plot) {
          plot->addCurve(vc);
        }
      }
  
      if (_w->_curvePlacement->newPlot()) {
        QString name = w->createPlot(KST::suggestPlotName());

        if (_w->_curvePlacement->reGrid()) {
          w->view()->cleanup(_w->_curvePlacement->columns());
        }
        plot = kst_cast<Kst2DPlot>(w->view()->findChild(name));
        if (plot) {
          _w->_curvePlacement->update();
          _w->_curvePlacement->setCurrentPlot(plot->tagName());
          plot->addCurve(vc);
          plot->generateDefaultLabels();
        }
      }
    }
  
    KST::dataObjectList.lock().writeLock();
    KST::dataObjectList.append(hs);
    KST::dataObjectList.append(vc);
    KST::dataObjectList.lock().unlock();
  
    hs = 0L;
    vc = 0L;

    emit modified();
  }

  return true;
}