void KstCurveDialogI::edit_I() { int index; KstVCurvePtr curve; KstVCurveList curves = kstObjectSubList<KstDataObject, KstVCurve>(KST::dataObjectList); index = Select->currentItem(); if (index < 0 || unsigned(index) >= curves.count()) { new_I(); return; } QString tag_name = Select->currentText(); /* verify that the curve name is unique */ if (tag_name != curves[index]->tagName()) { if (KST::dataTagNameNotUnique(tag_name)) { Select->setFocus(); return; } } curve = curves[index]; curve->setTagName(tag_name); { // leave this scope here to destroy the iterator KstReadLocker ml(&KST::vectorList.lock()); KstVectorList::Iterator i = KST::vectorList.findTag(_xVector->selectedVector()); if (i != KST::vectorList.end()) curve->setXVector(*i); i = KST::vectorList.findTag(_yVector->selectedVector()); if (i != KST::vectorList.end()) curve->setYVector(*i); i = KST::vectorList.findTag(_xError->selectedVector()); curve->setXError(*i); i = KST::vectorList.findTag(_yError->selectedVector()); curve->setYError(*i); } curve->setColor(_curveAppearance->color()); curve->setHasPoints(_curveAppearance->showPoints()); curve->setHasLines(_curveAppearance->showLines()); curve->setLineWidth(_curveAppearance->lineWidth()); curve->setLineStyle(_curveAppearance->lineStyle()); curve->Point.setType(_curveAppearance->pointType()); curve->update(-1); curve = 0L; curves.clear(); emit modified(); }
void KstEqDialog::fillFieldsForNew() { KstEquationList eqs; KstVCurveList curves; eqs = kstObjectSubList<KstDataObject, KstEquation>(KST::dataObjectList); curves = kstObjectSubList<KstDataObject, KstVCurve>(KST::dataObjectList); _tagName->setText(defaultTag); _legendText->setText(defaultTag); _legendText->show(); _legendLabel->show(); _w->_curvePlacement->update(); // // set the X Axis Vector to the X axis vector of // the last curve on the global curve list... // if (curves.count() > 0) { _w->_xVectors->setSelection(curves.last()->xVTag().displayString()); } _w->_equation->clear(); // // for some reason the lower widget needs to be shown first to prevent overlapping? // _w->_curveAppearance->hide(); _w->_curvePlacement->show(); _w->_curveAppearance->show(); _w->_curveAppearance->reset(); adjustSize(); resize(minimumSizeHint()); setFixedHeight(height()); }
QColor KstColorSequence::next(const KstVCurveList& curves, const QColor& badColor) { QColor color; int dark_factor; int ptrMin; int start; if (!_self) { _self = sdColorSequence.setObject(_self, new KstColorSequence); } _self->createPalette(); QMemArray<int> usage(_self->_count*2); for (int i = 0; i < _self->_count*2; i++) { usage[i] = 0; } // check we are not already using this color, but if // we are then count the number of usages of each color // in the palette. start = _self->_ptr; if (start >= _self->_count * 2) { start = 0; } while (_self->_ptr != start) { if (_self->_ptr >= _self->_count * 2) { _self->_ptr = 0; } dark_factor = 100 + ( 50 * ( _self->_ptr / _self->_count ) ); color = _self->_pal->color( _self->_ptr % _self->_count).dark(dark_factor); // if we are too close to the bad color then increase the usage count // to try and not use it. if (badColor.isValid() && colorsTooClose(color, badColor) ) { usage[_self->_ptr] += 100; } for (int i = 0; i < (int)curves.count(); i++) { if (color == curves[i]->color()) { usage[_self->_ptr]++; } } if (usage[_self->_ptr] == 0) { break; } _self->_ptr++; } // if we are already using this color then use the least used color for all the curves. if (usage[_self->_ptr] != 0) { ptrMin = _self->_ptr; while (_self->_ptr != start) { if (_self->_ptr >= _self->_count * 2) { _self->_ptr = 0; } if (usage[_self->_ptr] < usage[ptrMin]) { ptrMin = _self->_ptr; } _self->_ptr++; } _self->_ptr = ptrMin; } dark_factor = 100 + ( 50 * ( _self->_ptr / _self->_count ) ); color = _self->_pal->color( _self->_ptr++ % _self->_count).dark(dark_factor); return color; }
void KstCurveDialogI::update(int new_index) { int i_curve; KstVCurvePtr curve; int index; bool isNew = false; int n_v, n_c; KstVCurveList curves = kstObjectSubList<KstDataObject, KstVCurve>(KST::dataObjectList); if (new_index == -1) { if (curves.findTag(Select->currentText()) != curves.end()) { QString save = Select->currentText(); Select->blockSignals(true); Select->clear(); for (KstVCurveList::iterator i = curves.begin(); i != curves.end(); ++i) { Select->insertItem((*i)->tagName()); } Select->setCurrentText(save); Select->blockSignals(false); return; } } /**********************/ /* initialize indexes */ KST::vectorList.lock().readLock(); n_v = KST::vectorList.count(); KST::vectorList.lock().readUnlock(); n_c = curves.count(); if (new_index == -2) { // initialize for new curve isNew = true; index = n_c; } else if (n_c < 1) { isNew = true; index = 0; } else if (new_index >= 0 && new_index < n_c) { // initialize specific curve index = new_index; } else if (Select->count() > 0) { // initialize for old default index = Select->currentItem(); } else { // initialize for last in list index = n_c - 1; } /*****************************************/ /* fill the Select combo with curve tags */ Select->clear(); for (KstVCurveList::iterator i = curves.begin(); i != curves.end(); ++i) { Select->insertItem((*i)->tagName()); } if (isNew) { QString new_label; new_label.sprintf("C%d-", curves.count()+1); new_label += i18n("<New_Curve>"); Select->insertItem(new_label); } if ((index>=0) && (index<Select->count())) { Select->setCurrentItem(index); } /*******************************************/ /* fill the Vector lists with vector names */ _xVector->update(); _yVector->update(); _xError->update(); _yError->update(); /***********************************/ /* set the curve placement window */ _curvePlacement->setPlotList(KST::plotList.tagNames(), true); _curvePlacement->setColumns(KST::plotList.getPlotCols()); if (isNew) { // guess what placement option is wanted if (!KST::plotList.isEmpty() && curves.count() > KST::plotList.count()) { _curvePlacement->setNewPlot(false); _curvePlacement->setExistingPlot(true); } else { _curvePlacement->setNewPlot(true); _curvePlacement->setExistingPlot(false); } } /****************************************************/ /* set the vector pull downs to the correct vectors */ if (n_c > 0 && !isNew) { i_curve = Select->currentItem(); curve = curves[i_curve]; _xVector->setSelection(curve->getXVTag()); _yVector->setSelection(curve->getYVTag()); _xError->setSelection(curve->getXETag()); _yError->setSelection(curve->getYETag()); _curveAppearance->setValue(curve->hasLines(), curve->hasPoints(), curve->getColor(), curve->Point.getType()); Delete->setEnabled(curve->getUsage() == 2); } else { /* no curves defined - initialize what we can to vector 0 */ _curveAppearance->reset(); Delete->setEnabled(false); } }