void KstEqDialog::fillFieldsForEdit() { KstEquationPtr ep; ep = kst_cast<KstEquation>(_dp); if (!ep) { return; // shouldn't be needed } // re-parse to get the latest equation ep->writeLock(); ep->reparse(); ep->unlock(); ep->readLock(); _tagName->setText(ep->tagName()); _w->_equation->setText(ep->equation()); _w->_doInterpolation->setChecked(ep->doInterp()); if (ep->vXIn()) { _w->_xVectors->setSelection(ep->vXIn()->tag().displayString()); } ep->unlock(); _w->_curveAppearance->hide(); _w->_curvePlacement->hide(); _legendText->hide(); _legendLabel->hide(); adjustSize(); resize(minimumSizeHint()); setFixedHeight(height()); }
bool KstEqDialogI::editSingleObject(KstEquationPtr eqPtr) { eqPtr->writeLock(); if (!checkEntries()) { eqPtr->unlock(); return false; } // update the vector only if it is dirty KstVectorPtr vp; if (_xVectorsDirty) { KST::vectorList.lock().readLock(); /* find *V */ KstVectorList::Iterator i = KST::vectorList.findTag(_w->_xVectors->selectedVector()); if (i == KST::vectorList.end()) { kstdFatal() << "Bug in kst: the Vector field (Eq) " << "refers to a non existant vector..." << endl; } vp = *i; } else { vp = eqPtr->vX(); } KST::vectorList.lock().unlock(); // update the DoInterpolation only if it is dirty if (_doInterpolationDirty) { eqPtr->setExistingXVector(vp, _w->_doInterpolation->isChecked()); } else { eqPtr->setExistingXVector(vp, eqPtr->doInterp()); } if (_equationDirty) { eqPtr->setEquation(_w->_equation->text()); if (!eqPtr->isValid()) { QString parseErrors; for (QStringList::ConstIterator i = Equation::errorStack.begin(); i != Equation::errorStack.end(); ++i) { parseErrors += *i; parseErrors += "\n"; } KMessageBox::detailedSorry(this, i18n("There is an error in the equation you entered."), parseErrors); eqPtr->unlock(); return false; } } eqPtr->unlock(); return true; }
bool KstEqDialogI::editObject() { KstEquationList eqList = kstObjectSubList<KstDataObject,KstEquation>(KST::dataObjectList); // if editing multiple objects, edit each one if (_editMultipleMode) { // if the user selected no vector, treat it as non-dirty _xVectorsDirty = _w->_xVectors->_vector->currentItem() != 0; _equationDirty = !_w->_equation->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 KstEquationList::Iterator eqIter = eqList.findTag(_editMultipleWidget->_objectList->text(i)); if (eqIter == eqList.end()) { return false; } KstEquationPtr eqPtr = *eqIter; if (!editSingleObject(eqPtr)) { return false; } didEdit = true; } } if (!didEdit) { KMessageBox::sorry(this, i18n("Select one or more objects to edit.")); return false; } } else { // verify that the curve name is unique QString tag_name = _tagName->text(); KstEquationPtr ep = kst_cast<KstEquation>(_dp); if (!ep || tag_name != ep->tagName() && KstData::self()->dataTagNameNotUnique(tag_name)) { _tagName->setFocus(); return false; } ep->writeLock(); ep->setTagName(tag_name); ep->unlock(); // then edit the object _equationDirty = true; _xVectorsDirty = true; _doInterpolationDirty = true; if (!editSingleObject(ep)) { return false; } } emit modified(); return true; }
bool KstEqDialog::editObject() { KstEquationList eqList; eqList = kstObjectSubList<KstDataObject,KstEquation>(KST::dataObjectList); if (_editMultipleMode) { // // if the user selected no vector, treat it as non-dirty... // _xVectorsDirty = _w->_xVectors->_vector->currentIndex() != 0; _equationDirty = !_w->_equation->text().isEmpty(); bool didEdit = false; int i; for (i = 0; i < _editMultipleWidget->_objectList->count(); i++) { if (_editMultipleWidget->_objectList->item(i)->isSelected()) { KstEquationList::iterator eqIter; KstEquationPtr eqPtr; eqIter = eqList.findTag(_editMultipleWidget->_objectList->item(i)->text()); if (eqIter == eqList.end()) { return false; } eqPtr = *eqIter; if (!editSingleObject(eqPtr)) { return false; } didEdit = true; } } if (!didEdit) { QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("Select one or more objects to edit.")); return false; } } else { QString tagName = _tagName->text(); KstEquationPtr ep; // // verify that the curve name is unique... // ep = kst_cast<KstEquation>(_dp); if (!ep || (tagName != ep->tagName() && KstData::self()->dataTagNameNotUnique(tagName))) { _tagName->setFocus(); return false; } ep->writeLock(); ep->setTagName(tagName); ep->unlock(); // // then edit the object... // _equationDirty = true; _xVectorsDirty = true; _doInterpolationDirty = true; if (!editSingleObject(ep)) { return false; } } emit modified(); return true; }
bool KstEqDialog::editSingleObject(KstEquationPtr eqPtr) { KstVectorPtr vp; eqPtr->writeLock(); if (!checkEntries()) { eqPtr->unlock(); return false; } if (_xVectorsDirty) { KstVectorList::iterator i; KST::vectorList.lock().readLock(); i = KST::vectorList.findTag(_w->_xVectors->selectedVector()); if (i != KST::vectorList.end()) { vp = *i; } KST::vectorList.lock().unlock(); } else { vp = eqPtr->vX(); } // // update the _doInterpolation only if it is dirty... // if (_doInterpolationDirty) { eqPtr->setExistingXVector(vp, _w->_doInterpolation->isChecked()); } else { eqPtr->setExistingXVector(vp, eqPtr->doInterp()); } if (_equationDirty) { eqPtr->setEquation(_w->_equation->text()); if (!eqPtr->isValid()) { QStringList::const_iterator i; QString strWarning = QObject::tr("There is an error in the equation you entered.\n"); for (i = Equation::errorStack.begin(); i != Equation::errorStack.end(); ++i) { strWarning += *i; strWarning += "\n"; } QMessageBox::warning(this, QObject::tr("Kst"), strWarning); eqPtr->unlock(); return true; } eqPtr->setRecursed(false); if (eqPtr->recursion()) { eqPtr->setRecursed(true); eqPtr->unlock(); QMessageBox::critical(this, QObject::tr("Kst"), QObject::tr("There is a recursion resulting from the equation you entered.")); return false; } } eqPtr->unlock(); return true; }