Ejemplo n.º 1
0
void Datapicker::addNewPoint(const QPointF& pos, AbstractAspect* parentAspect) {
	QList<DatapickerPoint*> childPoints = parentAspect->children<DatapickerPoint>(AbstractAspect::IncludeHidden);
	if (childPoints.isEmpty())
		beginMacro(i18n("%1: add new point", parentAspect->name()));
	else
		beginMacro(i18n("%1: add new point %2", parentAspect->name(), childPoints.count()));

	DatapickerPoint* newPoint = new DatapickerPoint(i18n("%1 Point", parentAspect->name()));
	newPoint->setPosition(pos);
	newPoint->setHidden(true);
	parentAspect->addChild(newPoint);
	newPoint->retransform();

	DatapickerCurve* datapickerCurve = dynamic_cast<DatapickerCurve*>(parentAspect);
	if (m_image == parentAspect) {
		DatapickerImage::ReferencePoints points = m_image->axisPoints();
		points.scenePos[childPoints.count()].setX(pos.x());
		points.scenePos[childPoints.count()].setY(pos.y());
		m_image->setAxisPoints(points);
	} else if (datapickerCurve) {
		newPoint->initErrorBar(datapickerCurve->curveErrorTypes());
		datapickerCurve->updateData(newPoint);
	}

	endMacro();
	emit requestUpdateActions();
}
Ejemplo n.º 2
0
//! Load from XML
bool DatapickerCurve::load(XmlStreamReader* reader) {
	Q_D(DatapickerCurve);

	if(!reader->isStartElement() || reader->name() != "datapickerCurve") {
		reader->raiseError(i18n("no dataPicker curve element found"));
		return false;
	}

	if (!readBasicAttributes(reader))
		return false;

	QString attributeWarning = i18n("Attribute '%1' missing or empty, default value is used");
	QXmlStreamAttributes attribs;
	QString str;

	while (!reader->atEnd()) {
		reader->readNext();
		if (reader->isEndElement() && reader->name() == "datapickerCurve")
			break;

		if (!reader->isStartElement())
			continue;

		if (reader->name() == "comment") {
			if (!readCommentElement(reader)) return false;
		} else if (reader->name() == "general") {
			attribs = reader->attributes();

			str = attribs.value("curveErrorType_X").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("curveErrorType_X"));
			else
				d->curveErrorTypes.x = ErrorType(str.toInt());

			str = attribs.value("curveErrorType_Y").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("curveErrorType_Y"));
			else
				d->curveErrorTypes.y = ErrorType(str.toInt());

			READ_COLUMN(posXColumn);
			READ_COLUMN(posYColumn);
			READ_COLUMN(posZColumn);
			READ_COLUMN(plusDeltaXColumn);
			READ_COLUMN(minusDeltaXColumn);
			READ_COLUMN(plusDeltaYColumn);
			READ_COLUMN(minusDeltaYColumn);

		} else if(reader->name() == "symbolProperties") {
			attribs = reader->attributes();

			str = attribs.value("pointRotationAngle").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointRotationAngle"));
			else
				d->pointRotationAngle = str.toFloat();

			str = attribs.value("pointOpacity").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointOpacity"));
			else
				d->pointOpacity = str.toFloat();

			str = attribs.value("pointSize").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointSize"));
			else
				d->pointSize = str.toFloat();

			str = attribs.value("pointStyle").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointStyle"));
			else
				d->pointStyle = (Symbol::Style)str.toInt();

			str = attribs.value("pointVisibility").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointVisibility"));
			else
				d->pointVisibility = (bool)str.toInt();

			READ_QBRUSH(d->pointBrush);
			READ_QPEN(d->pointPen);
		} else if(reader->name() == "errorBarProperties") {
			attribs = reader->attributes();

			str = attribs.value("pointErrorBarSize").toString();
			if(str.isEmpty())
				reader->raiseWarning(attributeWarning.arg("pointErrorBarSize"));
			else
				d->pointErrorBarSize = str.toFloat();

			READ_QBRUSH(d->pointErrorBarBrush);
			READ_QPEN(d->pointErrorBarPen);
		} else if (reader->name() == "datapickerPoint") {
			DatapickerPoint* curvePoint = new DatapickerPoint("");
			curvePoint->setHidden(true);
			if (!curvePoint->load(reader)) {
				delete curvePoint;
				return false;
			} else {
				addChild(curvePoint);
				curvePoint->initErrorBar(curveErrorTypes());
			}
		} else if (reader->name() == "spreadsheet") {
			Spreadsheet* datasheet = new Spreadsheet(0, "spreadsheet", true);
			if (!datasheet->load(reader)) {
				delete datasheet;
				return false;
			} else {
				addChild(datasheet);
				m_datasheet = datasheet;
			}
		} else { // unknown element
			reader->raiseWarning(i18n("unknown element '%1'", reader->name().toString()));
			if (!reader->skipToEndElement()) return false;
		}
	}

	d->retransform();
	return true;
}