Beispiel #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;
}
Beispiel #2
0
void KstHsDialog::populateEditMultiple() {
  KstHistogramList hslist;

  hslist = kstObjectSubList<KstDataObject,KstHistogram>(KST::dataObjectList);
  _editMultipleWidget->_objectList->insertItems(0, hslist.tagNames());

  _w->Min->setText("");
  _w->Max->setText("");

  _w->N->setMinimum(_w->N->minimum() - 1);
  _w->N->setSpecialValueText(" ");
  _w->N->setValue(_w->N->minimum());

  _w->_vector->_vector->insertItem(0, "");
  _w->_vector->_vector->setCurrentIndex(0);
  _w->_realTimeAutoBin->setTristate(true);
  _w->_realTimeAutoBin->setChecked(Qt::PartiallyChecked);

  _w->NormIsPercent->setChecked(false);
  _w->NormIsFraction->setChecked(false);
  _w->PeakIs1->setChecked(false);
  _w->NormIsNumber->setChecked(false);
  _tagName->setText("");
  _tagName->setEnabled(false);
  _w->AutoBin->setEnabled(false);

  _w->Min->setEnabled(true);
  _w->Max->setEnabled(true);

  _minDirty = false;
  _maxDirty = false;
  _nDirty = false;
  _vectorDirty = false;
  _realTimeAutoBinDirty = false;
  _normIsPercentDirty = false;
  _normIsFractionDirty = false;
  _peakIs1Dirty = false;
  _normIsNumberDirty = false;
}
Beispiel #3
0
void KstHsDialogI::populateEditMultiple() {
  KstHistogramList hslist = kstObjectSubList<KstDataObject,KstHistogram>(KST::dataObjectList);
  _editMultipleWidget->_objectList->insertStringList(hslist.tagNames());

  // also intermediate state for multiple edit
  _w->Min->setText("");
  _w->Max->setText("");

  _w->N->setMinValue(_w->N->minValue() - 1);
  _w->N->setSpecialValueText(" ");
  _w->N->setValue(_w->N->minValue());

  _w->_vector->_vector->insertItem("", 0);
  _w->_vector->_vector->setCurrentItem(0);
  _w->_realTimeAutoBin->setTristate(true);
  _w->_realTimeAutoBin->setNoChange();

  _w->NormIsPercent->setChecked(false);
  _w->NormIsFraction->setChecked(false);
  _w->PeakIs1->setChecked(false);
  _w->NormIsNumber->setChecked(false);
  _tagName->setText("");
  _tagName->setEnabled(false);
  _w->AutoBin->setEnabled(false);

  _w->Min->setEnabled(true);
  _w->Max->setEnabled(true);

  // and clean all the fields
  _minDirty = false;
  _maxDirty = false;
  _nDirty = false;
  _vectorDirty = false;
  _realTimeAutoBinDirty = false;
  _normIsPercentDirty = false;
  _normIsFractionDirty = false;
  _peakIs1Dirty = false;
  _normIsNumberDirty = false;
}
Beispiel #4
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;
}
Beispiel #5
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;
}