コード例 #1
0
ファイル: DiagramScene.cpp プロジェクト: JobstM/ogs
/// Adjusts the underlying grid based on the graphs that are displayed in the diagram
void DiagramScene::constructGrid()
{
	// be very careful with scaling parameters here!
	int numXTicks, numYTicks;
	float xMin = _unscaledBounds.left();
	float yMin = _unscaledBounds.top();
	float xMax = _unscaledBounds.right();
	float yMax = _unscaledBounds.bottom();

	adjustAxis(xMin, xMax, numXTicks);
	adjustAxis(yMin, yMax, numYTicks);

	// adjust boundaries of coordinate system according to scaling
	_bounds.setRect(    xMin * _scaleX,
	                    yMin * _scaleY,
	                    (xMax - xMin) * _scaleX,
	                    (yMax - yMin) * _scaleY
	                    );

	QPen pen(Qt::black, 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin);
	_grid = addGrid(_bounds, numXTicks, numYTicks, pen);

	if (_startDate == QDateTime())
	{
		for (int i = 0; i <= numXTicks; ++i)
		{
			int x = static_cast<int>(_bounds.left() / _scaleX +
									 (i * (_bounds.width() / _scaleX) / numXTicks));
			_xTicksText.push_back(addNonScalableText(QString::number(x)));
			_xTicksText.last()->setPos(x * _scaleX, _bounds.bottom() + 15);
		}
	}
	else
	{
		for (int i = 0; i <= numXTicks; ++i)
		{
			int x = static_cast<int>(_bounds.left() / _scaleX +
									 (i * (_bounds.width() / _scaleX) / numXTicks));
			QDateTime currentDate = _startDate.addSecs(x);
			_xTicksText.push_back(addNonScalableText(currentDate.toString("dd.MM.yyyy")));
			_xTicksText.last()->setPos(x * _scaleX, _bounds.bottom() + 15);
		}
	}

	for (int j = 0; j <= numYTicks; ++j)
	{
		float y     = _bounds.bottom() / _scaleY -
		              (j * (_bounds.height() / _scaleY) / numYTicks);
		float label = _bounds.top()   / _scaleY +
		              (j * (_bounds.height() / _scaleY) / numYTicks);
		_yTicksText.push_back(addNonScalableText(QString::number(label)));
		_yTicksText.last()->setPos(_bounds.left() - MARGIN / 2, y * _scaleY);
	}
}
コード例 #2
0
ファイル: DiagramScene.cpp プロジェクト: JobstM/ogs
/// Initialises the coordinate axes, adds labels and/or units to the axes,
/// calculates axes-lengths, offsets, etc.
void DiagramScene::initialize()
{
	QPen pen(Qt::black, 2, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin);
	pen.setCosmetic(true);

	setXAxis(addArrow(_bounds.width(),  0, pen));
	setYAxis(addArrow(_bounds.height(), -90, pen));
	_xLabel = addNonScalableText(" ");
	_yLabel = addNonScalableText(" ");
	_yLabel->rotate(-90);

	_xUnit = addNonScalableText(" ");
	_yUnit = addNonScalableText(" ");

	update();
}
コード例 #3
0
ファイル: StratScene.cpp プロジェクト: UFZ-MJ/ogs
void StratScene::addDepthLabels(std::vector<GeoLib::Point*> profile, double offset)
{
	QRectF textBounds;
	double vertPos = MARGIN;
	std::vector<QNonScalableGraphicsTextItem*> depthText;
	depthText.push_back(addNonScalableText(QString::number((*(profile[0]))[2])));
	textBounds = depthText[0]->boundingRect();
	depthText[0]->setPos(offset + textBounds.width() / 2, vertPos);

	for (std::size_t i = 1; i < profile.size(); i++)
	{
		depthText.push_back(addNonScalableText(QString::number((*(profile[i]))[2])));
		vertPos += log((*(profile[i - 1]))[2] - (*(profile[i]))[2] + 1) * 100;
		textBounds = depthText[i]->boundingRect();
		depthText[i]->setPos(offset + textBounds.width() / 2, vertPos);
	}
}
コード例 #4
0
ファイル: StratScene.cpp プロジェクト: UFZ-MJ/ogs
void StratScene::addSoilNameLabels(std::vector<std::string> soilNames,
                                   std::vector<GeoLib::Point*> profile,
                                   double offset)
{
	//QRectF textBounds;
	double vertPos = MARGIN, halfHeight = 0;
	std::vector<QNonScalableGraphicsTextItem*> soilText;
	soilText.push_back(addNonScalableText(QString::fromStdString(soilNames[0])));
	//textBounds = soilText[0]->boundingRect();
	soilText[0]->setPos(offset /* - textBounds.width() */, vertPos);

	for (std::size_t i = 1; i < soilNames.size(); i++)
	{
		soilText.push_back(addNonScalableText(QString::fromStdString(soilNames[i])));
		halfHeight = log((*(profile[i - 1]))[2] - (*(profile[i]))[2] + 1) * 100 / 2;
		//textBounds = soilText[i]->boundingRect();
		soilText[i]->setPos(offset /* - textBounds.width() */, vertPos + halfHeight);
		vertPos += ( 2 * halfHeight );
	}
}
コード例 #5
0
ファイル: StratScene.cpp プロジェクト: UFZ-MJ/ogs
StratScene::StratScene(GeoLib::StationBorehole* station,
                       std::map<std::string, GeoLib::Color*>* stratColors,
                       QObject* parent) : QGraphicsScene(parent)
{
	QRectF textBounds;
	int stratBarOffset = 250;

	QFont font( "Arial", 15, QFont::DemiBold, false);

	QNonScalableGraphicsTextItem* boreholeTag = addNonScalableText("Borehole", font);
	QNonScalableGraphicsTextItem* boreholeName = addNonScalableText(
	        "\"" + QString::fromStdString(station->getName()) + "\"",
	        font);
	textBounds = boreholeTag->boundingRect();
	boreholeTag->setPos((textBounds.width() / 2.0), 80);
	textBounds = boreholeName->boundingRect();
	boreholeName->setPos((textBounds.width() / 2.0), 200);

	QNonScalableGraphicsTextItem* totalDepth =
	        addNonScalableText("Depth: " + QString::number(station->getDepth()) + " m");
	textBounds = totalDepth->boundingRect();
	totalDepth->setPos((textBounds.width() / 2.0), 350);
/*
    QNonScalableGraphicsTextItem* dateText = addNonScalableText("Date: " + QString::fromStdString(date2string(station->getDate())));
    textBounds = dateText->boundingRect();
    dateText->setPos(this->MARGIN + (textBounds.width()/2.0), 350);
 */
	QNonScalableGraphicsTextItem* dot = addNonScalableText(" ");
	dot->setPos(0, 0);

	StratBar* stratBar = addStratBar(station, stratColors);
	stratBar->setPos(stratBarOffset, MARGIN);
	QRectF stratBarBounds = stratBar->boundingRect();

	addDepthLabels(station->getProfile(), stratBarOffset + stratBarBounds.width());

	if (station->getSoilNames().size() > 0)
		addSoilNameLabels(station->getSoilNames(), station->getProfile(), stratBarOffset +
		                  (stratBarBounds.width() / 2));
}