bool KstIfaceImpl::setPlotAxes(const QString& plotName, int XLower, int XUpper, int YLower, int YUpper) { //find the plot KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *iter = app->createIterator(); while (iter->currentItem()) { KMdiChildView *childview = iter->currentItem(); KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview); if (viewwindow) { Kst2DPlotList plotlist = viewwindow->view()->findChildrenType<Kst2DPlot>(false); Kst2DPlotList::Iterator plot_iter=plotlist.findTag(plotName); if (plot_iter != plotlist.end()) { app->deleteIterator(iter); (*plot_iter)->setXScaleMode(FIXED); (*plot_iter)->setYScaleMode(FIXED); (*plot_iter)->setScale(XLower, YLower, XUpper, YUpper); //set the scale // repaint the plot (*plot_iter)->setDirty(); viewwindow->view()->paint(KstPainter::P_PLOT); return true; } } iter->next(); } app->deleteIterator(iter); return false; }
void KstImageDialogI::placeInPlot(KstImagePtr image) { KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText())); if (!w) { QString n = KstApp::inst()->newWindow(KST::suggestWinName()); w = static_cast<KstViewWindow*>(KstApp::inst()->findWindow(n)); } if (w) { Kst2DPlotPtr plot; if (_w->_curvePlacement->existingPlot()) { /* assign image to plot */ plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName())); if (plot) { plot->addCurve(KstBaseCurvePtr(image)); } } if (_w->_curvePlacement->newPlot()) { /* assign image to plot */ QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName()); if (_w->_curvePlacement->reGrid()) { w->view()->cleanup(_w->_curvePlacement->columns()); } plot = kst_cast<Kst2DPlot>(w->view()->findChild(name)); if (plot) { _w->_curvePlacement->update(); _w->_curvePlacement->setCurrentPlot(plot->tagName()); plot->setXScaleMode(AUTO); plot->setYScaleMode(AUTO); plot->addCurve(KstBaseCurvePtr(image)); plot->generateDefaultLabels(); } } } }
KJS::Object KstBindLegend::construct(KJS::ExecState *exec, const KJS::List& args) { if (args.size() == 0 || args.size() > 2) { return createSyntaxError(exec); } KstViewObjectPtr view = extractViewObject(exec, args[0]); if (!view) { KstViewWindow *w = extractWindow(exec, args[0]); if (w) { view = w->view(); } else { return createTypeError(exec, 0); } } QString txt; if (args.size() == 2) { if (args[1].type() != KJS::StringType) { return createTypeError(exec, 1); } txt = args[1].toString(exec).qstring(); } KstViewLegendPtr b = new KstViewLegend; view->appendChild(b.data()); KstApp::inst()->paintAll(KstPainter::P_PAINT); return KJS::Object(new KstBindLegend(exec, b)); }
int KstGuiData::columns(const QString& window) { KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(window)); if (w) { KstTopLevelViewPtr view = w->view(); if (view->onGrid()) { return view->columns(); } } return -1; }
QStringList KstIfaceImpl::plotList(const QString& window) { QStringList rc; KstApp *app = KstApp::inst(); KMdiChildView *c = app->findWindow(window); KstViewWindow *v = dynamic_cast<KstViewWindow*>(c); if (v) { Kst2DPlotList l = v->view()->findChildrenType<Kst2DPlot>(false); for (Kst2DPlotList::Iterator i = l.begin(); i != l.end(); ++i) { rc += (*i)->tagName(); } } return rc; }
void KstObjectItem::paintPlot(Kst2DPlotPtr p) { KstApp *app = KstApp::inst(); QList<KMdiChildView*> childViews = app->childViews(); QListIterator<KMdiChildView*> it(childViews); while (it.hasNext()) { KstViewWindow *v = dynamic_cast<KstViewWindow*>(it.next()); if (v && v->view()->contains(kst_cast<KstViewObject>(p))) { v->view()->paint(KstPainter::P_PLOT); break; } it.next(); } }
void KstObjectItem::paintPlot(Kst2DPlotPtr p) { KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *it = app->createIterator(); while (it->currentItem()) { KstViewWindow *v = dynamic_cast<KstViewWindow*>(it->currentItem()); if (v && v->view()->contains(kst_cast<KstViewObject>(p))) { v->view()->paint(KstPainter::P_PLOT); break; } it->next(); } app->deleteIterator(it); }
KstViewLegendList KstViewLegend::globalLegendList() { KstViewLegendList rc; KstApp *app = KstApp::inst(); QListIterator<KMdiChildView*> it(app->childViews()); while (it.hasNext()) { KstViewWindow *view = dynamic_cast<KstViewWindow*>(it.next()); if (view) { KstViewLegendList sub = view->view()->findChildrenType<KstViewLegend>(true); rc += sub; } it.next(); } return rc; }
bool KstFilterDialogI::createCurve(KstCPluginPtr plugin) { KstVectorPtr xVector; KstVectorPtr yVector; KST::vectorList.lock().readLock(); KstVectorList::Iterator it = KST::vectorList.findTag(_xvector); if (it != KST::vectorList.end()) { xVector = *it; } KST::vectorList.lock().unlock(); if (plugin->outputVectors().contains(plugin->plugin()->data()._filterOutputVector)) { yVector = plugin->outputVectors()[plugin->plugin()->data()._filterOutputVector]; } if (!xVector || !yVector) { return false; } plugin->setDirty(); QString c_name = KST::suggestCurveName(plugin->tag(), true); QColor color = KstApp::inst()->chooseColorDlg()->getColorForCurve(KstVectorPtr(xVector), KstVectorPtr(yVector)); if (!color.isValid()) { color = _w->_curveAppearance->color(); } KstVCurvePtr fit = new KstVCurve(c_name, KstVectorPtr(xVector), KstVectorPtr(yVector), KstVectorPtr(0L), KstVectorPtr(0L), KstVectorPtr(0L), KstVectorPtr(0L), color); fit->setHasPoints(_w->_curveAppearance->showPoints()); fit->setHasLines(_w->_curveAppearance->showLines()); fit->setHasBars(_w->_curveAppearance->showBars()); fit->setLineWidth(_w->_curveAppearance->lineWidth()); fit->setLineStyle(_w->_curveAppearance->lineStyle()); fit->setPointStyle(_w->_curveAppearance->pointType()); fit->setBarStyle(_w->_curveAppearance->barStyle()); fit->setPointDensity(_w->_curveAppearance->pointDensity()); KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_window)); if (w && w->view()->findChild(_plotName)) { Kst2DPlotPtr plot = kst_cast<Kst2DPlot>(w->view()->findChild(_plotName)); if (plot) { plot->addCurve(fit.data()); } } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(fit.data()); KST::dataObjectList.lock().unlock(); return true; }
bool KstGuiData::viewObjectNameNotUnique(const QString& tag) { KstApp *app = KstApp::inst(); QList<QWidget*> childViews = app->childViews(); QListIterator<KMdiChildView*> it(childViews); while (it.hasNext()) { KstViewWindow *view = dynamic_cast<KstViewWindow*>(it.next()); if (view) { if (view->view()->findChild(tag, true)) { return (true); } } it.next(); } return false; }
bool KstGuiData::viewObjectNameNotUnique(const QString& tag) { KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *it = app->createIterator(); if (it) { while (it->currentItem()) { KstViewWindow *view = dynamic_cast<KstViewWindow*>(it->currentItem()); if (view) { if (view->view()->findChild(tag, true)) { return (true); } } it->next(); } app->deleteIterator(it); } return false; }
bool KstIfaceImpl::deletePlot(const QString& window, const QString& name) { KstViewWindow *pView = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(window)); if (pView) { KstTopLevelViewPtr pTLV = pView->view(); KstViewObjectList objects = pTLV->findChildrenType<KstViewObject>(true); for (KstViewObjectList::Iterator it = objects.begin(); it != objects.end(); ++it) { KstViewObjectPtr object = *it; if (object->tagName() == name) { pTLV->removeChild(object, true); _doc->forceUpdate(); _doc->setModified(); return true; } } } return false; }
bool KstIfaceImpl::toggleMaximizePlot(const QString& plotName) { KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *iter = app->createIterator(); while (iter->currentItem()) { KMdiChildView *childview = iter->currentItem(); KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview); if (viewwindow) { Kst2DPlotList plotlist = viewwindow->view()->findChildrenType<Kst2DPlot>(false); Kst2DPlotList::Iterator plot_iter = plotlist.findTag(plotName); if (plot_iter != plotlist.end()) { app->deleteIterator(iter); (*plot_iter)->zoomToggle(); return true; } } iter->next(); } app->deleteIterator(iter); return false; }
KJS::Object KstBindLine::construct(KJS::ExecState *exec, const KJS::List& args) { if (args.size() != 1) { return createSyntaxError(exec); } KstViewObjectPtr view = extractViewObject(exec, args[0]); if (!view) { KstViewWindow *w = extractWindow(exec, args[0]); if (w) { view = w->view(); } else { return createTypeError(exec, 0); } } KstViewLinePtr b = new KstViewLine; view->appendChild(b.data()); KstApp::inst()->paintAll(KstPainter::P_PAINT); return KJS::Object(new KstBindLine(exec, b)); }
QStringList KstIfaceImpl::plotContents(const QString& name) { //iterate through the windows until plot is found KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *iter = app->createIterator(); while (iter->currentItem()) { KMdiChildView *childview = iter->currentItem(); KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview); if (viewwindow) { Kst2DPlotList plotlist = viewwindow->view()->findChildrenType<Kst2DPlot>(false); Kst2DPlotList::Iterator plot_iter=plotlist.findTag(name); if (plot_iter != plotlist.end()) { app->deleteIterator(iter); return (*plot_iter)->Curves.tagNames(); } } iter->next(); } app->deleteIterator(iter); return QStringList(); }
KJS::Object KstBindPlot::construct(KJS::ExecState *exec, const KJS::List& args) { KstViewWindow *w = 0L; if (args.size() == 1) { w = extractWindow(exec, args[0]); if (!w) { return createTypeError(exec, 0); } } else { return createSyntaxError(exec); } QString n = w->createPlotObject(KST::suggestPlotName(), false); Kst2DPlotPtr p = *w->view()->findChildrenType<Kst2DPlot>(true).findTag(n); if (!p) { return createGeneralError(exec, i18n("Failed to create plot.")); } w->view()->paint(KstPainter::P_PAINT); return KJS::Object(new KstBindPlot(exec, p)); }
bool KstIfaceImpl::removeCurveFromPlot(KMdiChildView *win, const QString& plot, const QString& curve) { KstViewWindow *w = dynamic_cast<KstViewWindow*>(win); if (w) { KstTopLevelViewPtr view = kst_cast<KstTopLevelView>(w->view()); if (view) { Kst2DPlotList plots = view->findChildrenType<Kst2DPlot>(true); if (plots.findTag(plot) != plots.end()) { Kst2DPlotPtr p = *(plots.findTag(plot)); KstBaseCurveList bcl = kstObjectSubList<KstDataObject,KstBaseCurve>(KST::dataObjectList); KstBaseCurveList::Iterator ci = bcl.findTag(curve); if (p && ci != bcl.end()) { p->removeCurve(*ci); _doc->forceUpdate(); return true; } } } } return false; }
KstImagePtr KstCsdDialogI::createImage(KstCSDPtr csd) { KPalette* newPal = new KPalette(_w->_colorPalette->selectedPalette()); csd->readLock(); KstImagePtr image = new KstImage(csd->tagName()+"-I", csd->outputMatrix(), 0, 1, true, newPal); csd->unlock(); KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText())); if (!w) { QString n = KstApp::inst()->newWindow(KST::suggestWinName()); w = static_cast<KstViewWindow*>(KstApp::inst()->findWindow(n)); } if (w) { Kst2DPlotPtr plot; if (_w->_curvePlacement->existingPlot()) { /* assign image to plot */ plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName())); if (plot) { plot->addCurve(KstBaseCurvePtr(image)); } } if (_w->_curvePlacement->newPlot()) { /* assign image to plot */ QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName()); if (_w->_curvePlacement->reGrid()) { w->view()->cleanup(_w->_curvePlacement->columns()); } plot = kst_cast<Kst2DPlot>(w->view()->findChild(name)); if (plot) { _w->_curvePlacement->update(); _w->_curvePlacement->setCurrentPlot(plot->tagName()); plot->addCurve(KstBaseCurvePtr(image)); plot->generateDefaultLabels(); } } } return image; }
bool KstIfaceImpl::addPlotMarker(const QString &plotName, double markerValue) { //find the plot KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *iter = app->createIterator(); while (iter->currentItem()) { KMdiChildView *childview = iter->currentItem(); KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview); if (viewwindow) { Kst2DPlotList plotlist = viewwindow->view()->findChildrenType<Kst2DPlot>(false); Kst2DPlotList::Iterator plot_iter=plotlist.findTag(plotName); if (plot_iter != plotlist.end() && (*plot_iter)->setPlotMarker(markerValue)) { app->deleteIterator(iter); // repaint the plot (*plot_iter)->setDirty(); viewwindow->view()->paint(KstPainter::P_PLOT); return true; } } iter->next(); } app->deleteIterator(iter); return false; }
KJS::Object KstBindEllipse::construct(KJS::ExecState *exec, const KJS::List& args) { if (args.size() != 1) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError); exec->setException(eobj); return KJS::Object(); } KstViewObjectPtr view = extractViewObject(exec, args[0]); if (!view) { KstViewWindow *w = extractWindow(exec, args[0]); if (w) { view = w->view(); } else { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } } KstViewEllipsePtr b = new KstViewEllipse; view->appendChild(b.data()); KstApp::inst()->paintAll(KstPainter::P_PAINT); return KJS::Object(new KstBindEllipse(exec, b)); }
void KstCurveDifferentiateI::apply() { KstApp *app = KstApp::inst(); KstViewWindow *window; int maxSequences = 0; getOptions(); saveProperties(); _seqVect.clear(); _seqVect.resize(4); if (_lineColorOrder > -1) { _lineColorSeq.setRange(0, KstColorSequence::count()); _seqVect.insert(_lineColorOrder, &_lineColorSeq); maxSequences++; } if (_pointStyleOrder > -1) { _pointStyleSeq.setRange(0, KSTPOINT_MAXTYPE - 1); _seqVect.insert(_pointStyleOrder, &_pointStyleSeq); maxSequences++; } if (_lineStyleOrder > -1) { _lineStyleSeq.setRange(0, KSTLINESTYLE_MAXTYPE - 1); _seqVect.insert(_lineStyleOrder, &_lineStyleSeq); maxSequences++; } if (_lineWidthOrder > -1) { _lineWidthSeq.setRange(1, KSTLINEWIDTH_MAX); _seqVect.insert(_lineWidthOrder, &_lineWidthSeq); maxSequences++; } if (maxSequences > 0) { int i; _seqVect.resize(maxSequences); for (i = 0; i < maxSequences-1; i++) { _seqVect[i]->hookToNextSequence(_seqVect[i+1]); } _seqVect[maxSequences-1]->hookToNextSequence(0L); if (_applyTo == 0) { window = dynamic_cast<KstViewWindow*>(app->activeWindow()); if (window) { cycleWindow(window); } } else { KMdiIterator<KMdiChildView*> *it = app->createIterator(); if (it) { while (it->currentItem()) { if (_repeatAcross == 1) { _seqVect[0]->reset(); } window = dynamic_cast<KstViewWindow*>(it->currentItem()); if (window && !window->view()->children().isEmpty()) { cycleWindow(window); } it->next(); } app->deleteIterator(it); } } } close(); }
bool KstEqDialogI::newObject() { QString tag_name = _tagName->text(); QString etext = _w->_equation->text(); etext.remove(QRegExp("[^a-zA-Z0-9\\(\\)\\+\\-\\*/\\%\\^\\|\\&\\!<>=_.]")); if (etext.length() > 12) { etext.truncate(12); etext += "..."; } if (tag_name == defaultTag) { tag_name = KST::suggestEQName(etext); } /* verify that the curve name is unique */ if (KstData::self()->dataTagNameNotUnique(tag_name)) { _tagName->setFocus(); return false; } if (!checkEntries()) { return false; } KST::vectorList.lock().readLock(); /* find *V */ KstVectorPtr vp = *KST::vectorList.findTag(_w->_xVectors->selectedVector()); if (!vp) { kstdFatal() << "Bug in kst: the Vector field (Eq) " << "refers to a non-existent vector..." << endl; } KST::vectorList.lock().unlock(); /** Create the equation here */ vp->readLock(); KstEquationPtr eq = new KstEquation(tag_name, _w->_equation->text(), vp, _w->_doInterpolation->isChecked()); vp->unlock(); if (!eq->isValid()) { eq = 0L; 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); return false; } KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(tag_name, true), eq->vX(), eq->vY(), 0L, 0L, 0L, 0L, _w->_curveAppearance->color()); vc->setHasPoints(_w->_curveAppearance->showPoints()); vc->setHasLines(_w->_curveAppearance->showLines()); vc->setHasBars(_w->_curveAppearance->showBars()); vc->setLineWidth(_w->_curveAppearance->lineWidth()); vc->setLineStyle(_w->_curveAppearance->lineStyle()); vc->pointType = _w->_curveAppearance->pointType(); vc->setPointDensity(_w->_curveAppearance->pointDensity()); vc->setBarStyle(_w->_curveAppearance->barStyle()); QString legend_text = _legendText->text(); if (legend_text == defaultTag) { vc->setLegendText(QString("")); } else { vc->setLegendText(legend_text); } KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText())); if (!w) { QString n = KstApp::inst()->newWindow(KST::suggestWinName()); w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(n)); } if (w) { Kst2DPlotPtr plot; if (_w->_curvePlacement->existingPlot()) { /* assign curve to plot */ plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName())); if (plot) { plot->addCurve(vc.data()); } } if (_w->_curvePlacement->newPlot()) { /* assign curve to plot */ QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName()); if (_w->_curvePlacement->reGrid()) { w->view()->cleanup(_w->_curvePlacement->columns()); } plot = kst_cast<Kst2DPlot>(w->view()->findChild(name)); if (plot) { _w->_curvePlacement->update(); _w->_curvePlacement->setCurrentPlot(plot->tagName()); plot->addCurve(vc.data()); plot->generateDefaultLabels(); } } } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eq.data()); KST::dataObjectList.append(vc.data()); KST::dataObjectList.lock().unlock(); eq = 0L; // drop the reference before we update vc = 0L; emit modified(); return true; }
bool KstChangeFileDialogI::applyFileChange() { KstDataSourcePtr file; KST::dataSourceList.lock().writeLock(); KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_dataFile->url()); QString invalidSources; int invalid = 0; if (it == KST::dataSourceList.end()) { file = KstDataSource::loadSource(_dataFile->url()); if (!file || !file->isValid()) { KST::dataSourceList.lock().unlock(); KMessageBox::sorry(this, i18n("The file could not be loaded.")); return false; } if (file->isEmpty()) { KST::dataSourceList.lock().unlock(); KMessageBox::sorry(this, i18n("The file does not contain data.")); return false; } KST::dataSourceList.append(file); } else { file = *it; } KST::dataSourceList.lock().unlock(); KstApp *app = KstApp::inst(); KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); KstRMatrixList rml = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList); int selected = 0; int handled = 0; int count = (int)ChangeFileCurveList->count(); for (int i = 0; i < count; i++) { if (ChangeFileCurveList->isSelected(i)) { ++selected; } } // a map to keep track of which objects have been duplicated, and mapping // old object -> new object KstDataObjectDataObjectMap duplicatedMap; QMap<KstVectorPtr, KstVectorPtr> duplicatedVectors; QMap<KstMatrixPtr, KstMatrixPtr> duplicatedMatrices; KstDataSourceList oldSources; // go through the vectors for (int i = 0; i < (int)rvl.count(); i++) { if (ChangeFileCurveList->isSelected(i)) { KstRVectorPtr vector = rvl[i]; vector->writeLock(); file->readLock(); bool valid = file->isValidField(vector->field()); file->unlock(); if (!valid) { if (invalid > 0) { // FIXME: invalid list construction for i18n invalidSources = i18n("%1, %2").arg(invalidSources).arg(vector->field()); } else { invalidSources = vector->field(); } ++invalid; } else { if (_duplicateSelected->isChecked()) { // block vector updates until vector is setup properly KST::vectorList.lock().writeLock(); // create a new vector KstRVectorPtr newVector = vector->makeDuplicate(); if (!oldSources.contains(newVector->dataSource())) { oldSources << newVector->dataSource(); } newVector->changeFile(file); KST::vectorList.lock().unlock(); // duplicate dependents if (_duplicateDependents->isChecked()) { duplicatedVectors.insert(KstVectorPtr(vector), KstVectorPtr(newVector)); KST::duplicateDependents(KstVectorPtr(vector), duplicatedMap, duplicatedVectors); } } else { if (!oldSources.contains(vector->dataSource())) { oldSources << vector->dataSource(); } vector->changeFile(file); } } vector->unlock(); app->slotUpdateProgress(selected, ++handled, i18n("Updating vectors...")); } } // go through the matrices for (int i = (int)rvl.count(); i < (int)ChangeFileCurveList->count(); i++) { if (ChangeFileCurveList->isSelected(i)) { KstRMatrixPtr matrix = rml[i-rvl.count()]; matrix->writeLock(); file->readLock(); bool valid = file->isValidMatrix(matrix->field()); file->unlock(); if (!valid) { if (invalid > 0) { // FIXME: invalid list construction for i18n invalidSources = i18n("%1, %2").arg(invalidSources).arg(matrix->field()); } else { invalidSources = matrix->field(); } ++invalid; } else { if (_duplicateSelected->isChecked()) { // block matrix updates until matrix is setup properly KST::matrixList.lock().writeLock(); // create a new matrix KstRMatrixPtr newMatrix = matrix->makeDuplicate(); if (!oldSources.contains(newMatrix->dataSource())) { oldSources << newMatrix->dataSource(); } newMatrix->changeFile(file); KST::matrixList.lock().unlock(); // duplicate dependents if (_duplicateDependents->isChecked()) { duplicatedMatrices.insert(KstMatrixPtr(matrix), KstMatrixPtr(newMatrix)); KST::duplicateDependents(KstMatrixPtr(matrix), duplicatedMap, duplicatedMatrices); } } else { if (!oldSources.contains(matrix->dataSource())) { oldSources << matrix->dataSource(); } matrix->changeFile(file); } } matrix->unlock(); app->slotUpdateProgress(selected, ++handled, i18n("Updating matrices...")); } } app->slotUpdateProgress(0, 0, QString::null); file = 0L; // now add any curves and images to plots if they were duplicated if (_duplicateSelected->isChecked() && _duplicateDependents->isChecked()) { KstApp *app = KstApp::inst(); KMdiIterator<KMdiChildView*> *it = app->createIterator(); while (it->currentItem()) { KstViewWindow *w = dynamic_cast<KstViewWindow*>(it->currentItem()); if (w) { KstTopLevelViewPtr view = kst_cast<KstTopLevelView>(w->view()); if (view) { Kst2DPlotList plots = view->findChildrenType<Kst2DPlot>(true); for (Kst2DPlotList::Iterator plotIter = plots.begin(); plotIter != plots.end(); ++plotIter) { for (KstDataObjectDataObjectMap::ConstIterator iter = duplicatedMap.begin(); iter != duplicatedMap.end(); ++iter) { if (KstBaseCurvePtr curve = kst_cast<KstBaseCurve>(iter.data())) { if ((*plotIter)->Curves.contains(kst_cast<KstBaseCurve>(iter.key())) && !(*plotIter)->Curves.contains(kst_cast<KstBaseCurve>(curve))) { (*plotIter)->addCurve(curve); } } } } } } it->next(); } app->deleteIterator(it); } // clean up unused data sources // kstdDebug() << "cleaning up data sources" << endl; KST::dataSourceList.lock().writeLock(); for (KstDataSourceList::Iterator it = oldSources.begin(); it != oldSources.end(); ++it) { // kstdDebug() << "DATA SOURCE: " << (*it)->tag().displayString() << " (" << (void*)(*it) << ") USAGE: " << (*it)->getUsage() << endl; if ((*it)->getUsage() == 1) { // kstdDebug() << " -> REMOVED" << endl; KST::dataSourceList.remove((*it).data()); } } KST::dataSourceList.lock().unlock(); if (!invalidSources.isEmpty()) { if (invalid == 1) { KMessageBox::sorry(this, i18n("The following field is not defined for the requested file:\n%1").arg(invalidSources)); } else { KMessageBox::sorry(this, i18n("The following fields are not defined for the requested file:\n%1").arg(invalidSources)); } } emit docChanged(); // force an update in case we're in paused mode KstApp::inst()->forceUpdate(); return true; }
bool KstEqDialog::newObject() { QString tag_name = _tagName->text(); QString etext = _w->_equation->text(); etext.remove(QRegExp("[^a-zA-Z0-9\\(\\)\\+\\-\\*/\\%\\^\\|\\&\\!<>=_.]")); etext.replace(KstObjectTag::tagSeparator, KstObjectTag::tagSeparatorReplacement); if (etext.length() > 12) { etext.truncate(12); etext += "..."; } if (tag_name == defaultTag) { tag_name = KST::suggestEQName(etext); } if (KstData::self()->dataTagNameNotUnique(tag_name)) { _tagName->setFocus(); return false; } if (!checkEntries()) { return false; } KST::vectorList.lock().readLock(); KstVectorPtr vp = *KST::vectorList.findTag(_w->_xVectors->selectedVector()); if (vp) { KST::vectorList.lock().unlock(); KstEquationPtr eq; eq = new KstEquation(tag_name, _w->_equation->text(), vp, _w->_doInterpolation->isChecked()); if (!eq->isValid()) { QStringList::const_iterator i; QString strWarning = QObject::tr("There is an error in the equation you entered.\n"); eq = 0L; for (i = Equation::errorStack.begin(); i != Equation::errorStack.end(); ++i) { strWarning += *i; strWarning += "\n"; } QMessageBox::warning(this, QObject::tr("Kst"), strWarning); return false; } KstVCurvePtr vc; QColor color; // xxx color = KstApp::inst()->chooseColorDlg()->getColorForCurve(eq->vX(), eq->vY()); if (!color.isValid()) { color = _w->_curveAppearance->color(); } vc = new KstVCurve(KST::suggestCurveName(eq->tag(), true), eq->vX(), eq->vY(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), color); vc->setHasPoints(_w->_curveAppearance->showPoints()); vc->setHasLines(_w->_curveAppearance->showLines()); vc->setHasBars(_w->_curveAppearance->showBars()); vc->setLineWidth(_w->_curveAppearance->lineWidth()); vc->setLineStyle(_w->_curveAppearance->lineStyle()); vc->setPointStyle(_w->_curveAppearance->pointType()); vc->setPointDensity(_w->_curveAppearance->pointDensity()); vc->setBarStyle(_w->_curveAppearance->barStyle()); QString legend_text = _legendText->text(); if (legend_text == defaultTag) { vc->setLegendText(QString("")); } else { vc->setLegendText(legend_text); } KstViewWindow *w; /* xxx w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText())); if (!w) { QString n = KstApp::inst()->newWindow(KST::suggestWinName()); w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(n)); } */ if (w) { Kst2DPlotPtr plot; if (_w->_curvePlacement->existingPlot()) { plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName())); if (plot) { plot->addCurve(vc); } } if (_w->_curvePlacement->newPlot()) { QString name = w->createPlot(KST::suggestPlotName()); if (_w->_curvePlacement->reGrid()) { w->view()->cleanup(_w->_curvePlacement->columns()); } plot = kst_cast<Kst2DPlot>(w->view()->findChild(name)); if (plot) { _w->_curvePlacement->update(); _w->_curvePlacement->setCurrentPlot(plot->tagName()); plot->addCurve(vc); plot->generateDefaultLabels(); } } } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eq); KST::dataObjectList.append(vc); KST::dataObjectList.lock().unlock(); // // drop the reference before we update... // eq = 0L; vc = 0L; emit modified(); } return true; }
bool KstPsdDialog::newObject() { QString tag_name = _tagName->text(); bool retVal = false; if (tag_name == defaultTag) { tag_name = KST::suggestPSDName(KstObjectTag::fromString(_w->_vector->selectedVector())); } if (KstData::self()->dataTagNameNotUnique(tag_name)) { _tagName->setFocus(); return false; } if (_w->_vector->selectedVector().isEmpty()) { QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("New spectrum not made: define vectors first.")); return false; } KST::vectorList.lock().readLock(); KstVectorPtr p = *KST::vectorList.findTag(_w->_vector->selectedVector()); KST::vectorList.lock().unlock(); if (_w->_kstFFTOptions->checkValues()) { if (p) { KstVCurvePtr vc; KstPSDPtr psd; QColor color; p->readLock(); psd = new KstPSD(tag_name, p, _w->_kstFFTOptions->SampRate->text().toDouble(), _w->_kstFFTOptions->Interleaved->isChecked(), _w->_kstFFTOptions->FFTLen->text().toInt(), _w->_kstFFTOptions->Apodize->isChecked(), _w->_kstFFTOptions->RemoveMean->isChecked(), _w->_kstFFTOptions->VectorUnits->text(), _w->_kstFFTOptions->RateUnits->text(), ApodizeFunction(_w->_kstFFTOptions->ApodizeFxn->currentIndex()), _w->_kstFFTOptions->Sigma->value(), PSDType(_w->_kstFFTOptions->Output->currentIndex())); psd->setInterpolateHoles(_w->_kstFFTOptions->InterpolateHoles->isChecked()); p->unlock(); // xxx color = KstApp::inst()->chooseColorDlg()->getColorForCurve(psd->vX(), psd->vY()); if (!color.isValid()) { color = _w->_curveAppearance->color(); } vc = new KstVCurve(KST::suggestCurveName(psd->tag(),true), psd->vX(), psd->vY(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), color); vc->setHasPoints(_w->_curveAppearance->showPoints()); vc->setHasLines(_w->_curveAppearance->showLines()); vc->setHasBars(_w->_curveAppearance->showBars()); vc->setPointStyle(_w->_curveAppearance->pointType()); vc->setLineWidth(_w->_curveAppearance->lineWidth()); vc->setLineStyle(_w->_curveAppearance->lineStyle()); vc->setBarStyle(_w->_curveAppearance->barStyle()); vc->setPointDensity(_w->_curveAppearance->pointDensity()); QString legend_text = _legendText->text(); if (legend_text == defaultTag) { vc->setLegendText(QString::null); } else { vc->setLegendText(legend_text); } Kst2DPlotPtr plot; KstViewWindow *w; /* xxx w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText())); if (!w) { QString n = KstApp::inst()->newWindow(KST::suggestWinName()); w = static_cast<KstViewWindow*>(KstApp::inst()->findWindow(n)); } */ if (w) { if (_w->_curvePlacement->existingPlot()) { plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName())); if (plot) { plot->addCurve(vc); } } if (_w->_curvePlacement->newPlot()) { QString name = w->createPlot(KST::suggestPlotName()); if (_w->_curvePlacement->reGrid()) { w->view()->cleanup(_w->_curvePlacement->columns()); } plot = kst_cast<Kst2DPlot>(w->view()->findChild(name)); if (plot) { plot->setXAxisInterpretation(false, KstAxisInterpretation(), KstAxisDisplay()); plot->setYAxisInterpretation(false, KstAxisInterpretation(), KstAxisDisplay()); _w->_curvePlacement->update(); _w->_curvePlacement->setCurrentPlot(plot->tagName()); plot->addCurve(vc); plot->generateDefaultLabels(); } } } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(psd); KST::dataObjectList.append(vc); KST::dataObjectList.lock().unlock(); psd = 0L; vc = 0L; emit modified(); retVal = true; } } return retVal; }
/* returns true if succesful */ bool KstPsdDialogI::newObject() { QString tag_name = _tagName->text(); if (tag_name == defaultTag) { tag_name = KST::suggestPSDName(KstObjectTag::fromString(_w->_vector->selectedVector())); } // verify that the curve name is unique if (KstData::self()->dataTagNameNotUnique(tag_name)) { _tagName->setFocus(); return false; } if (_w->_vector->selectedVector().isEmpty()) { KMessageBox::sorry(this, i18n("New PSD not made: define vectors first.")); return false; } KST::vectorList.lock().readLock(); KstVectorPtr p = *KST::vectorList.findTag(_w->_vector->selectedVector()); KST::vectorList.lock().unlock(); if (!p) { kstdFatal() << "Bug in kst: the vector field (PSD) refers to " << "a non existant vector...." << endl; } // create the psd curve if (!_w->_kstFFTOptions->checkValues()) { return false; } else { p->readLock(); KstPSDPtr psd = new KstPSD(tag_name, p, _w->_kstFFTOptions->SampRate->text().toDouble(), _w->_kstFFTOptions->Interleaved->isChecked(), _w->_kstFFTOptions->FFTLen->text().toInt(), _w->_kstFFTOptions->Apodize->isChecked(), _w->_kstFFTOptions->RemoveMean->isChecked(), _w->_kstFFTOptions->VectorUnits->text(), _w->_kstFFTOptions->RateUnits->text(), ApodizeFunction(_w->_kstFFTOptions->ApodizeFxn->currentItem()), _w->_kstFFTOptions->Sigma->value(), PSDType(_w->_kstFFTOptions->Output->currentItem())); psd->setInterpolateHoles(_w->_kstFFTOptions->InterpolateHoles->isChecked()); p->unlock(); KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(psd->tag(),true), psd->vX(), psd->vY(), 0L, 0L, 0L, 0L, _w->_curveAppearance->color()); vc->setHasPoints(_w->_curveAppearance->showPoints()); vc->setHasLines(_w->_curveAppearance->showLines()); vc->setHasBars(_w->_curveAppearance->showBars()); vc->pointType = _w->_curveAppearance->pointType(); vc->setLineWidth(_w->_curveAppearance->lineWidth()); vc->setLineStyle(_w->_curveAppearance->lineStyle()); vc->setBarStyle(_w->_curveAppearance->barStyle()); vc->setPointDensity(_w->_curveAppearance->pointDensity()); QString legend_text = _legendText->text(); if (legend_text == defaultTag) { vc->setLegendText(QString::null); } else { vc->setLegendText(legend_text); } Kst2DPlotPtr plot; KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText())); if (!w) { QString n = KstApp::inst()->newWindow(KST::suggestWinName()); w = static_cast<KstViewWindow*>(KstApp::inst()->findWindow(n)); } if (w) { if (_w->_curvePlacement->existingPlot()) { // assign curve to plot plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName())); if (plot) { plot->addCurve(vc.data()); } } if (_w->_curvePlacement->newPlot()) { // assign curve to plot QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName()); if (_w->_curvePlacement->reGrid()) { w->view()->cleanup(_w->_curvePlacement->columns()); } plot = kst_cast<Kst2DPlot>(w->view()->findChild(name)); if (plot) { plot->setXAxisInterpretation(false, KstAxisInterpretation(), KstAxisDisplay()); plot->setYAxisInterpretation(false, KstAxisInterpretation(), KstAxisDisplay()); _w->_curvePlacement->update(); _w->_curvePlacement->setCurrentPlot(plot->tagName()); plot->addCurve(vc.data()); plot->generateDefaultLabels(); } } } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(psd.data()); KST::dataObjectList.append(vc.data()); KST::dataObjectList.lock().unlock(); psd = 0L; vc = 0L; emit modified(); } return true; }
bool KstHsDialog::newObject() { QString tag_name = _tagName->text(); if (tag_name == defaultTag) { tag_name = KST::suggestHistogramName(KstObjectTag::fromString(_w->_vector->selectedVector())); } // // verify that the curve name is unique... // if (KstData::self()->dataTagNameNotUnique(tag_name)) { _tagName->setFocus(); return false; } if (_w->_vector->selectedVector().isEmpty()) { QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("New Histogram not made: define vectors first.")); return false; } // // find max and min... // double new_min = _w->Min->text().toDouble(); double 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.")); return false; } int new_n_bins = _w->N->text().toInt(); if (new_n_bins < 1) { QMessageBox::warning(this, QObject::tr("kst"), QObject::tr("You must have one or more bins in a histogram.")); return false; } KstHsNormType new_norm_mode; if (_w->NormIsPercent->isChecked()) { new_norm_mode = KST_HS_PERCENT; } else if (_w->NormIsFraction->isChecked()) { new_norm_mode = KST_HS_FRACTION; } else if (_w->PeakIs1->isChecked()) { new_norm_mode = KST_HS_MAX_ONE; } else { new_norm_mode = KST_HS_NUMBER; } KstHistogramPtr hs; KST::vectorList.lock().readLock(); KstVectorPtr vp = *KST::vectorList.findTag(_w->_vector->selectedVector()); KST::vectorList.lock().unlock(); if (vp) { KstVCurvePtr vc; KstViewWindow *w; QColor color; vp->readLock(); hs = new KstHistogram(tag_name, vp, new_min, new_max, new_n_bins, new_norm_mode); vp->unlock(); hs->setRealTimeAutoBin(_w->_realTimeAutoBin->isChecked()); // xxx color = KstApp::inst()->chooseColorDlg()->getColorForCurve(hs->vX(), hs->vY()); if (!color.isValid()) { color = _w->_curveAppearance->color(); } vc = new KstVCurve(KST::suggestCurveName(hs->tag(), true), hs->vX(), hs->vY(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), KstVectorPtr(), color); vc->setHasPoints(_w->_curveAppearance->showPoints()); vc->setHasLines(_w->_curveAppearance->showLines()); vc->setHasBars(_w->_curveAppearance->showBars()); vc->setPointStyle(_w->_curveAppearance->pointType()); vc->setLineWidth(_w->_curveAppearance->lineWidth()); vc->setLineStyle(_w->_curveAppearance->lineStyle()); vc->setBarStyle(_w->_curveAppearance->barStyle()); vc->setPointDensity(_w->_curveAppearance->pointDensity()); QString legendText = _legendText->text(); if (legendText == defaultTag) { vc->setLegendText(QString("")); } else { vc->setLegendText(legendText); } /* xxx w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText())); */ if (!w) { QString n = KstApp::inst()->newWindow(KST::suggestWinName()); // xxx w = static_cast<KstViewWindow*>(KstApp::inst()->findWindow(n)); } if (w) { Kst2DPlotPtr plot; if (_w->_curvePlacement->existingPlot()) { plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName())); if (plot) { plot->addCurve(vc); } } if (_w->_curvePlacement->newPlot()) { QString name = w->createPlot(KST::suggestPlotName()); if (_w->_curvePlacement->reGrid()) { w->view()->cleanup(_w->_curvePlacement->columns()); } plot = kst_cast<Kst2DPlot>(w->view()->findChild(name)); if (plot) { _w->_curvePlacement->update(); _w->_curvePlacement->setCurrentPlot(plot->tagName()); plot->addCurve(vc); plot->generateDefaultLabels(); } } } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(hs); KST::dataObjectList.append(vc); KST::dataObjectList.lock().unlock(); hs = 0L; vc = 0L; emit modified(); } return true; }
bool KstIfaceImpl::plotEquation(const QString& xvector, const QString& equation, const QString& plotName, const QColor& color) { KstVectorPtr v; Kst2DPlotPtr plot; QString etag, ptag; KST::vectorList.lock().readLock(); KstVectorList::Iterator it = KST::vectorList.findTag(xvector); KST::vectorList.lock().unlock(); KstApp *app = KstApp::inst(); if (equation.isEmpty() || it == KST::vectorList.end()) { return false; } v = *it; etag = KST::suggestEQName(QString(equation).replace(QRegExp("[\\[\\]\\s]"), "_")); ptag = "P-" + plotName; if (!plotName.isEmpty()) { //find the plot, or P-plotName KMdiIterator<KMdiChildView*> *iter = app->createIterator(); bool found = false; while (iter->currentItem() && !found) { KMdiChildView *childview = iter->currentItem(); KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview); if (viewwindow && !found) { Kst2DPlotList plotlist = viewwindow->view()->findChildrenType<Kst2DPlot>(false); Kst2DPlotList::Iterator plot_iter = plotlist.findTag(plotName); if (plot_iter != plotlist.end()) { plot = *plot_iter; found = true; } else { Kst2DPlotList::Iterator plot_iter = plotlist.findTag(ptag); if (plot_iter != plotlist.end()) { plot = *plot_iter; found = true; } } } iter->next(); } app->deleteIterator(iter); } //if the plot does not exist, create it if (!plot) { //put the plot in the active window KMdiChildView *activewin = app->activeWindow(); if (!activewin) { QString windowname = app->newWindow("W1"); activewin = app->findWindow(windowname); } KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(activewin); if (viewwindow) { KstTopLevelViewPtr pTLV = viewwindow->view(); plot = pTLV->createObject<Kst2DPlot>(ptag); } } KstEquationPtr eq = new KstEquation(etag, equation, v, true); if (!eq->isValid()) { return false; } KstVCurveList vcurves = kstObjectSubList<KstBaseCurve,KstVCurve>(plot->Curves); KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(etag, true), eq->vX(), eq->vY(), 0L, 0L, 0L, 0L, color.isValid() ? color : KstColorSequence::next(vcurves,plot->backgroundColor())); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(KstDataObjectPtr(eq)); KST::dataObjectList.append(KstDataObjectPtr(vc)); KST::dataObjectList.lock().unlock(); plot->addCurve(KstBaseCurvePtr(vc)); _doc->forceUpdate(); _doc->setModified(); return true; }