/** fill the custom widget with current properties */ bool KstViewLegend::fillConfigWidget(QWidget *w, bool isNew) const { ViewLegendWidget *widget = dynamic_cast<ViewLegendWidget*>(w); if (!widget) { return false; } KstBaseCurveList allCurves = kstObjectSubList<KstDataObject, KstBaseCurve>(KST::dataObjectList); if (isNew) { widget->_fontSize->setValue(0); widget->_fontColor->setColor(KstSettings::globalSettings()->foregroundColor); widget->_font->setCurrentFont(KstApp::inst()->defaultFont()); widget->_margin->setValue(5); widget->_boxColors->setColor(KstSettings::globalSettings()->foregroundColor); widget->_vertical->setChecked(true); widget->_transparent->setChecked(false); widget->_border->setValue(2); widget->_title->setText(""); widget->TrackContents->setChecked(true); for (KstBaseCurveList::ConstIterator it = allCurves.begin(); it != allCurves.end(); ++it) { (*it)->readLock(); widget->AvailableCurveList->insertItem((*it)->tagName()); (*it)->unlock(); } } else { // fill legend properties into widget widget->TrackContents->setChecked(trackContents()); widget->_title->setText(title()); widget->_fontSize->setValue(int(fontSize())); widget->_fontColor->setColor(foregroundColor()); widget->_font->setCurrentFont(fontName()); widget->_transparent->setChecked(transparent()); widget->_border->setValue(borderWidth()); widget->_boxColors->setColor(borderColor()); widget->_margin->setValue(_legendMargin); widget->_vertical->setChecked(vertical()); for (KstBaseCurveList::ConstIterator it = _curves.begin(); it != _curves.end(); ++it) { (*it)->readLock(); widget->DisplayedCurveList->insertItem((*it)->tagName()); (*it)->unlock(); } for (KstBaseCurveList::ConstIterator it = allCurves.begin(); it != allCurves.end(); ++it) { (*it)->readLock(); if (_curves.find(*it) == _curves.end()) { widget->AvailableCurveList->insertItem((*it)->tagName()); } (*it)->unlock(); } } return false; }
KstViewLegend::KstViewLegend(const QDomElement& e) : KstBorderedViewObject(e) { // some defaults and invariants _fallThroughTransparency = false; _container = false; _type = "Legend"; _rotation = 0.0; _fontName = KstApp::inst()->defaultFont(); _vertical = true; _isResizable = false; _fontSize = -1; setFontSize(0); _layoutActions &= ~(MoveTo | Copy | CopyTo); _standardActions |= Delete | Edit; _legendMargin = 5; _parsedTitle = 0L; _trackContents = true; QStringList ctaglist; // read the properties QDomNode n = e.firstChild(); while (!n.isNull()) { QDomElement el = n.toElement(); if (!el.isNull()) { if (metaObject()->indexOfProperty(el.tagName().toLatin1()) > -1) { setProperty(el.tagName().toLatin1(), QVariant(el.text())); } else if (el.tagName() == "curvetag") { ctaglist.append(el.text()); } } n = n.nextSibling(); } if (!_title.isEmpty()) { reparseTitle(); } KstBaseCurveList l = kstObjectSubList<KstDataObject,KstBaseCurve>(KST::dataObjectList); KstBaseCurveList::ConstIterator end = l.end(); for (QStringList::ConstIterator str = ctaglist.begin(); str != ctaglist.end(); ++str) { KstBaseCurveList::ConstIterator it = l.findTag(*str); if (it != end) { addCurve(*it); } } // Padding was incorrectly saved as 5 in Kst <= 1.2.0 so we need to strip it // out here since this object is buggy. Remove this once padding is properly // supported? Maybe, but geometries are then wrong. if (e.ownerDocument().documentElement().attribute("version") == "1.2") { setPadding(0); } }
QStringList KstIfaceImpl::curveList() { QStringList rc; KstBaseCurveList bcl = kstObjectSubList<KstDataObject,KstBaseCurve>(KST::dataObjectList); for (KstBaseCurveList::Iterator it = bcl.begin(); it != bcl.end(); ++it) { (*it)->readLock(); rc += (*it)->tagName(); (*it)->unlock(); } return rc; }
bool KstIfaceImpl::removeCurveFromPlot(const QString& plot, const QString& curve) { KstPlot *p = KST::plotList.FindKstPlot(plot); KstBaseCurveList bcl = kstObjectSubList<KstDataObject,KstBaseCurve>(KST::dataObjectList); KstBaseCurveList::Iterator ci = bcl.findTag(curve); if (p && ci != bcl.end()) { (*ci)->readLock(); p->Curves.remove(*ci); (*ci)->readUnlock(); _doc->forceUpdate(); _doc->setModified(); return true; } return false; }
bool KstIfaceImpl::addCurveToPlot(const QString& plot, const QString& curve) { KstPlot *p = KST::plotList.FindKstPlot(plot); KstBaseCurveList bcl = kstObjectSubList<KstDataObject,KstBaseCurve>(KST::dataObjectList); KstBaseCurveList::Iterator ci = bcl.findTag(curve); if (p && ci != bcl.end()) { if (!p->Curves.contains(*ci)) { p->addCurve(*ci); } _doc->forceUpdate(); _doc->setModified(); return true; } return false; }
/** apply properties in the custom config widget to this */ bool KstViewLegend::readConfigWidget(QWidget *w) { KstViewLegendList legends; KstViewLegendPtr legendExtra; ViewLegendWidget *widget = dynamic_cast<ViewLegendWidget*>(w); if (!widget) { return false; } if (widget->_thisLegend->isChecked()) { legends += this; } else if (widget->_thisWindow->isChecked()) { legends = topLevelParent()->findChildrenType<KstViewLegend>(true); } else { legends = globalLegendList(); } // apply the curve list, but only to this legend! KstBaseCurveList allCurves = kstObjectSubList<KstDataObject, KstBaseCurve>(KST::dataObjectList); _curves.clear(); for (unsigned i = 0; i < widget->DisplayedCurveList->count(); i++) { KstBaseCurveList::Iterator it = allCurves.findTag(widget->DisplayedCurveList->text(i)); if (it != allCurves.end()) { _curves.append(*it); } } for (uint i = 0; i < legends.size(); i++) { legendExtra = legends[i]; legendExtra->setFontSize(widget->_fontSize->value()); legendExtra->setForegroundColor(widget->_fontColor->color()); legendExtra->setFontName(widget->_font->currentFont().toString()); legendExtra->setTitle(widget->_title->text()); legendExtra->setTransparent(widget->_transparent->isChecked()); legendExtra->setBorderWidth(widget->_border->value()); legendExtra->setBorderColor(widget->_boxColors->color()); legendExtra->setBackgroundColor(widget->_boxColors->color()); legendExtra->setLegendMargin(widget->_margin->value()); legendExtra->setVertical(widget->_vertical->isChecked()); legendExtra->setTrackContents(widget->TrackContents->isChecked()); } setDirty(); return true; }
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; }