예제 #1
0
bool KstHsDialogI::editObject() {
  KstHistogramList hsList = kstObjectSubList<KstDataObject,KstHistogram>(KST::dataObjectList);

  // if editing multiple objects, edit each one
  if (_editMultipleMode) {
    // if the user selected no vector, treat it as non-dirty
    _vectorDirty = _w->_vector->_vector->currentItem() != 0;
    _nDirty = _w->N->text() != " ";
    _minDirty = !_w->Min->text().isEmpty();
    _maxDirty = !_w->Max->text().isEmpty();

    bool didEdit = false;
    for (uint i = 0; i < _editMultipleWidget->_objectList->count(); i++) {
      if (_editMultipleWidget->_objectList->isSelected(i)) {
        // get the pointer to the object
        KstHistogramList::Iterator hsIter = hsList.findTag(_editMultipleWidget->_objectList->text(i));
        if (hsIter == hsList.end()) {
          return false;
        }

        KstHistogramPtr hsPtr = *hsIter;

        if (!editSingleObject(hsPtr)) {
          return false;
        }
        didEdit = true;
      }
    }
    if (!didEdit) {
      KMessageBox::sorry(this, i18n("Select one or more objects to edit."));
      return false;
    }
  } else {
    KstHistogramPtr hp = kst_cast<KstHistogram>(_dp);
    // verify that the curve name is unique
    QString tag_name = _tagName->text();
    if (!hp || (tag_name != hp->tagName() && KstData::self()->dataTagNameNotUnique(tag_name))) {
      _tagName->setFocus();
      return false;
    }
    hp->setTagName(KstObjectTag(tag_name, hp->tag().context())); // FIXME: doesn't allow changing tag context

    // then edit the object
    _vectorDirty = true;
    _minDirty = true;
    _maxDirty = true;
    _nDirty = true;
    _realTimeAutoBinDirty = true;
    _normIsPercentDirty = true;
    _normIsFractionDirty = true;
    _peakIs1Dirty = true;
    _normIsNumberDirty = true;
    if (!editSingleObject(hp)) {
      return false;
    }
  }
  emit modified();
  return true;
}
예제 #2
0
void KstHsDialog::fillFieldsForEdit() {
  KstHistogramPtr hp;

  hp = kst_cast<KstHistogram>(_dp);
  if (hp) {
    hp->readLock();
  
    _tagName->setText(hp->tagName());
  
    _w->_vector->setSelection(hp->vTag());
  
    _w->N->setValue(hp->nBins());
    _w->Min->setText(QString::number(hp->vX()->min() - (hp->width()/2.0)));
    _w->Max->setText(QString::number(hp->vX()->max() + (hp->width()/2.0)));
    _w->_realTimeAutoBin->setChecked(hp->realTimeAutoBin());
  
    if (hp->isNormPercent()) {
      _w->NormIsPercent->setChecked(true);
    } else if (hp->isNormFraction()) {
      _w->NormIsFraction->setChecked(true);
    } else if (hp->isNormOne()) {
      _w->PeakIs1->setChecked(true);
    } else {
      _w->NormIsNumber->setChecked(true);
    }
  
  
    hp->unlock();
    updateButtons();
  
    // can't edit curve props from here....
    _w->_curveAppearance->hide();
    _w->_curvePlacement->hide();
    _legendText->hide();
    _legendLabel->hide();
  
    adjustSize();
    resize(minimumSizeHint());
    setFixedHeight(height());
  }
}
예제 #3
0
QStringList KstIfaceImpl::createHistogram(const QString& name,
                                          const QString& vector,
                                          double min,
                                          double max,
                                          int numBins,
                                          int normalizationType)
{
  //get the vector
  KST::vectorList.lock().readLock();
  KstVectorList::Iterator iter = KST::vectorList.findTag(vector);
  KST::vectorList.lock().unlock();

  if (iter == KST::vectorList.end()) {
    return QStringList();
  }

  //set the normalization type
  KstHsNormType normtype;

  switch (normalizationType) {
    case 1:
      normtype = KST_HS_NUMBER;
      break;
    case 2:
      normtype = KST_HS_PERCENT;
      break;
    case 3:
      normtype = KST_HS_FRACTION;
      break;
    case 4:
      normtype = KST_HS_MAX_ONE;
    default:
      normtype = KST_HS_NUMBER;
      break;
  }

  //suggest a name if not supplied
  QString htag_end;
  if (name.isEmpty())
    htag_end = QString(vector);
  else
    htag_end = QString(name);

  //count number of histograms and make a unique name
  KstHistogramList hlist = kstObjectSubList<KstDataObject,KstHistogram>(KST::dataObjectList);
  int i = hlist.count() + 1;
  QString stringnum;
  stringnum = stringnum.setNum(i);

  QString htag = stringnum + "-" + htag_end;

  while (KstData::self()->dataTagNameNotUnique(htag, false)) {
    stringnum.setNum(++i);
    htag = stringnum + "-" + htag_end;
  }

  KstHistogramPtr histogram = new KstHistogram(htag, *iter, min, max, numBins,
                                               normtype);

  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(KstDataObjectPtr(histogram));
  KST::dataObjectList.lock().unlock();

  QStringList returnList;
  returnList.push_back(histogram->tagName());
  returnList.push_back(histogram->xVTag());
  returnList.push_back(histogram->yVTag());
  
  _doc->forceUpdate();
  _doc->setModified();
  
  return returnList;
}
예제 #4
0
bool KstHsDialog::editObject() {
  KstHistogramList hsList;

  hsList = kstObjectSubList<KstDataObject,KstHistogram>(KST::dataObjectList);

  if (_editMultipleMode) {
    _vectorDirty = _w->_vector->_vector->currentIndex() != 0;
    _nDirty = _w->N->text() != " ";
    _minDirty = !_w->Min->text().isEmpty();
    _maxDirty = !_w->Max->text().isEmpty();

    bool didEdit = false;
    int i;

    for (i = 0; i < _editMultipleWidget->_objectList->count(); i++) {
      if (_editMultipleWidget->_objectList->item(i)->isSelected()) {
        KstHistogramList::iterator hsIter;
        KstHistogramPtr hsPtr;

        hsIter = hsList.findTag(_editMultipleWidget->_objectList->item(i)->text());
        if (hsIter == hsList.end()) {
          return false;
        }

        hsPtr = *hsIter;

        if (!editSingleObject(hsPtr)) {
          return false;
        }
        didEdit = true;
      }
    }
    if (!didEdit) {
      QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("Select one or more objects to edit."));
      return false;
    }
  } else {
    KstHistogramPtr hp;
    QString tag_name;

    hp = kst_cast<KstHistogram>(_dp);

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

    tag_name = _tagName->text();
    if (!hp || (tag_name != hp->tagName() && KstData::self()->dataTagNameNotUnique(tag_name))) {
      _tagName->setFocus();
      return false;
    }

    hp->writeLock();
    hp->setTagName(tag_name);
    hp->unlock();

    //
    // then edit the object...
    //

    _vectorDirty = true;
    _minDirty = true;
    _maxDirty = true;
    _nDirty = true;
    _realTimeAutoBinDirty = true;
    _normIsPercentDirty = true;
    _normIsFractionDirty = true;
    _peakIs1Dirty = true;
    _normIsNumberDirty = true;
    if (!editSingleObject(hp)) {
      return false;
    }
  }

  emit modified();

  return true;
}