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; }
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; }