void KstPsdDialogI::edit_I() { int index; KstPSDCurvePtr curve; double new_freq; int new_len; index = Select->currentItem(); KstPSDCurveList curves = kstObjectSubList<KstDataObject, KstPSDCurve>(KST::dataObjectList); if (index < 0 || unsigned(index) >= curves.count()) { new_I(); return; } curve = curves[index]; /* verify that the curve name is unique */ QString tag_name = Select->currentText(); if (tag_name != curve->tagName()) { if (KST::dataTagNameNotUnique(tag_name)) { Select->setFocus(); return; } } curve->setTagName(tag_name); KST::vectorList.lock().readLock(); curve->setVector(*KST::vectorList.findTag(_vector->selectedVector())); KST::vectorList.lock().readUnlock(); curve->setColor(_curveAppearance->color()); curve->setHasPoints(_curveAppearance->showPoints()); curve->setHasLines(_curveAppearance->showLines()); curve->Point.setType(_curveAppearance->pointType()); /* find new_freq */ new_freq = SampRate->text().toDouble(); if (new_freq <= 0) { KMessageBox::sorry(NULL, i18n("The sample rate must be greater than 0")); return; } /* find new_len */ new_len = FFTLen->text().toInt(); if (new_len<2) { KMessageBox::sorry(NULL, i18n("The FFT length must be greater than 2^2")); return; } curve->setFreq(new_freq); curve->setLen(new_len); curve->VUnits = VectorUnits->text(); curve->RUnits = RateUnits->text(); curve->setAppodize(Appodize->isChecked()); curve->setRemoveMean(RemoveMean->isChecked()); curve->update(); curve = 0L; curves.clear(); emit modified(); }
void KstPsdDialogI::new_I() { KstPSDCurvePtr curve; double new_freq; int new_len; QString tag_name = Select->currentText(); tag_name.replace(i18n("<New_PSD>"), "PSD_" + _vector->selectedVector()); /* verify that the curve name is unique */ if (KST::dataTagNameNotUnique(tag_name)) { Select->setFocus(); return; } if (_vector->selectedVector().isEmpty()) { KMessageBox::sorry(0L, i18n("New PSD not made: define vectors first.")); return; } /* find new_freq */ new_freq = SampRate->text().toDouble(); if (new_freq <= 0) { KMessageBox::sorry(0L, i18n("The sample rate must be greater than 0.")); return; } /* find new_len */ new_len = FFTLen->text().toInt(); if (new_len < 2) { KMessageBox::sorry(0L, i18n("The FFT length must be greater than 2^2.")); return; } { KST::vectorList.lock().readLock(); KstVectorList::Iterator i = KST::vectorList.findTag(_vector->selectedVector()); if (i == KST::vectorList.end()) { kdFatal() << "Bug in kst: the vector field in plotDialog (PSD) refers to " << "a non existant vector...." << endl; } KstVectorPtr p = *i; KST::vectorList.lock().readUnlock(); /* create the psd curve */ curve = new KstPSDCurve(tag_name, p, new_freq, new_len, VectorUnits->text(), RateUnits->text(), _curveAppearance->color()); } curve->setHasPoints(_curveAppearance->showPoints()); curve->setHasLines(_curveAppearance->showLines()); curve->Point.setType(_curveAppearance->pointType()); curve->setAppodize(Appodize->isChecked()); curve->setRemoveMean(RemoveMean->isChecked()); KstPlot *plot = 0L; if (_curvePlacement->existingPlot()) { /* assign curve to plot */ plot = KST::plotList.FindKstPlot(_curvePlacement->plotName()); plot->addCurve(curve); } if (_curvePlacement->newPlot()) { /* assign curve to plot */ plot = KST::plotList.addPlot(QString::null, _curvePlacement->columns()); _curvePlacement->appendPlot(plot->tagName(), true); plot->addCurve(curve); plot->GenerateDefaultLabels(); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(curve.data()); KST::dataObjectList.lock().writeUnlock(); curve = 0L; emit modified(); }