Example #1
0
// return raw(!) value of frontmost, active statistic item at given position
ValuePairList StatisticsObject::getValuesAt(int x, int y)
{
    ValuePairList valueList;

    for(int i=0; i<p_statsTypeList.count(); i++)
    {
        if (p_statsTypeList[i].render)  // only show active values
        {
            int typeID = p_statsTypeList[i].typeID;
            StatisticsItemList statsList = getStatistics(p_lastIdx, typeID);

            if( statsList.size() == 0 && typeID == INT_INVALID ) // no active statistics
                continue;

            StatisticsType* aType = getStatisticsType(typeID);
            Q_ASSERT(aType->typeID != INT_INVALID && aType->typeID == typeID);

            // find item of this type at requested position
            StatisticsItemList::iterator it;
            bool foundStats = false;
            for (it = statsList.begin(); it != statsList.end(); it++)
            {
                StatisticsItem anItem = *it;

                QRect aRect = anItem.positionRect;

                int rawValue1 = anItem.rawValues[0];
                int rawValue2 = anItem.rawValues[1];

                float vectorValue1 = anItem.vector[0];
                float vectorValue2 = anItem.vector[1];

                if( aRect.contains(x,y) )
                {
                    if( anItem.type == blockType )
                    {
                        valueList.append( ValuePair(aType->typeName, QString::number(rawValue1)) );
                    }
                    else if( anItem.type == arrowType )
                    {
                        // TODO: do we also want to show the raw values?
                        valueList.append( ValuePair(QString("%1[x]").arg(aType->typeName), QString::number(vectorValue1)) );
                        valueList.append( ValuePair(QString("%1[y]").arg(aType->typeName), QString::number(vectorValue2)) );
                    }

                    foundStats = true;
                }
            }

            if(!foundStats)
                valueList.append( ValuePair(aType->typeName, "-") );
        }
    }

    return valueList;
}
Example #2
0
void statisticSource::drawStatisticsImage(QPixmap *img, StatisticsItemList statsList, StatisticsType statsType)
{
	QPainter painter(img);

	StatisticsItemList::iterator it;
	for (it = statsList.begin(); it != statsList.end(); ++it)
	{
		StatisticsItem anItem = *it;

		switch (anItem.type)
		{
		case arrowType:
		{
			QRect aRect = anItem.positionRect;
			QRect displayRect = QRect(aRect.left()*p_internalScaleFactor, aRect.top()*p_internalScaleFactor, aRect.width()*p_internalScaleFactor, aRect.height()*p_internalScaleFactor);

			int x, y;

			// start vector at center of the block
			x = displayRect.left() + displayRect.width() / 2;
			y = displayRect.top() + displayRect.height() / 2;

			QPoint startPoint = QPoint(x, y);

			float vx = anItem.vector[0];
			float vy = anItem.vector[1];

			QPoint arrowBase = QPoint(x + p_internalScaleFactor*vx, y + p_internalScaleFactor*vy);
			QColor arrowColor = anItem.color;
			//arrowColor.setAlpha( arrowColor.alpha()*((float)statsType.alphaFactor / 100.0) );

			QPen arrowPen(arrowColor);
			painter.setPen(arrowPen);
			painter.drawLine(startPoint, arrowBase);

			if (vx == 0 && vy == 0)
			{
				// nothing to draw...
			}
			else
			{
				// draw an arrow
				float nx, ny;

				// TODO: scale arrow head with
				float a = p_internalScaleFactor * 4;    // length of arrow
				float b = p_internalScaleFactor * 2;    // base width of arrow

				float n_abs = sqrtf(vx*vx + vy*vy);
				float vxf = (float)vx / n_abs;
				float vyf = (float)vy / n_abs;

				QPoint arrowTip = arrowBase + QPoint(vxf*a + 0.5, vyf*a + 0.5);

				// arrow head right
				rotateVector((float)-M_PI_2, -vx, -vy, nx, ny);
				QPoint offsetRight = QPoint(nx*b + 0.5, ny*b + 0.5);
				QPoint arrowHeadRight = arrowBase + offsetRight;

				// arrow head left
				rotateVector((float)M_PI_2, -vx, -vy, nx, ny);
				QPoint offsetLeft = QPoint(nx*b + 0.5, ny*b + 0.5);
				QPoint arrowHeadLeft = arrowBase + offsetLeft;

				// draw arrow head
				QPoint points[3] = { arrowTip, arrowHeadRight, arrowHeadLeft };
				painter.setBrush(arrowColor);
				painter.drawPolygon(points, 3);
			}

			break;
		}
		case blockType:
		{
			//draw a rectangle
			QColor rectColor = anItem.color;
			rectColor.setAlpha(rectColor.alpha()*((float)statsType.alphaFactor / 100.0));
			painter.setBrush(rectColor);

			QRect aRect = anItem.positionRect;
			QRect displayRect = QRect(aRect.left()*p_internalScaleFactor, aRect.top()*p_internalScaleFactor, aRect.width()*p_internalScaleFactor, aRect.height()*p_internalScaleFactor);

			painter.fillRect(displayRect, rectColor);

			break;
		}
		}

		// optionally, draw a grid around the region
		if (statsType.renderGrid) {
			//draw a rectangle
			QColor gridColor = anItem.gridColor;
			QPen gridPen(gridColor);
			gridPen.setWidth(1);
			painter.setPen(gridPen);
			painter.setBrush(QBrush(QColor(Qt::color0), Qt::NoBrush));  // no fill color

			QRect aRect = anItem.positionRect;
			QRect displayRect = QRect(aRect.left()*p_internalScaleFactor, aRect.top()*p_internalScaleFactor, aRect.width()*p_internalScaleFactor, aRect.height()*p_internalScaleFactor);

			painter.drawRect(displayRect);
		}
	}
}