diff --git a/limereport/items/lrchartitem.cpp b/limereport/items/lrchartitem.cpp index 54df5c8..3dbeafa 100644 --- a/limereport/items/lrchartitem.cpp +++ b/limereport/items/lrchartitem.cpp @@ -144,7 +144,7 @@ ChartItem::ChartItem(QObject *owner, QGraphicsItem *parent) m_legendAlign(LegendAlignCenter), m_titleAlign(TitleAlignCenter), m_chartType(Pie), m_labelsField(""), m_isEmpty(true), m_showLegend(true), m_drawPoints(true), m_seriesLineWidth(4), - m_horizontalAxisOnTop(false) + m_horizontalAxisOnTop(false), m_gridChartLines(AllLines) { m_labels<<"First"<<"Second"<<"Thrid"; m_chart = new PieChart(this); @@ -508,6 +508,25 @@ void ChartItem::setHorizontalAxisOnTop(bool horizontalAxisOnTop) m_horizontalAxisOnTop = horizontalAxisOnTop; } +ChartItem::GridChartLines ChartItem::gridChartLines() const +{ + return m_gridChartLines; +} + +void ChartItem::setGridChartLines(GridChartLines flags) +{ + if (m_gridChartLines == flags) { + return; + } + GridChartLines oldValue = m_gridChartLines; + m_gridChartLines = flags; + if (isLoading()) { + return; + } + update(rect()); + notify("gridChartLines",QVariant(oldValue),QVariant(flags)); +} + AbstractChart::AbstractChart(ChartItem *chartItem) :m_chartItem(chartItem) { @@ -832,18 +851,25 @@ void AbstractSeriesChart::paintGrid(QPainter *painter, QRectF gridRect) const QTextOption verticalTextOption(Qt::AlignRight); for (int i = 0 ; i < yAxisLineCount ; i++ ) { const qreal y = vStep * i; + const bool drawFullLine = m_chartItem->gridChartLines() & ChartItem::HorizontalLine + || i == 0 || i == xAxisSegmentCount; painter->drawText(QRectF(gridRect.bottomLeft()-QPointF(halfFontHeight, y + halfFontHeight), QSizeF(valuesHMargin,fontHeight)), axisLabel(i, yAxisData), verticalTextOption); - painter->drawLine(gridRect.bottomLeft()-QPointF(-valuesHMargin, y), - gridRect.bottomRight()-QPointF(0, y)); + + QPointF lineEndPos = gridRect.bottomRight() - QPointF(0, y); + if (!drawFullLine) { + lineEndPos.setX(gridRect.left() + valuesHMargin + gridOffset); + } + painter->drawLine(gridRect.bottomLeft() - QPointF(-valuesHMargin, y), lineEndPos); } // Horizontal axis lines for (int i = 0 ; i < xAxisLineCount ; i++) { const qreal x = gridRect.left() + hStep * i + valuesHMargin + gridOffset; - const bool drawFullLine = i == 0 || i == xAxisSegmentCount; + const bool drawFullLine = m_chartItem->gridChartLines() & ChartItem::VerticalLine + || i == 0 || i == xAxisSegmentCount; const QString text = axisLabel(i, xAxisData); if (m_chartItem->horizontalAxisOnTop()) { @@ -1035,4 +1061,5 @@ QRectF AbstractBarChart::horizontalLabelsRect(QPainter *painter, QRectF labelsRe else return labelsRect.adjusted(0, (labelsRect.height() - maxWidth), 0, 0); } + } // namespace LimeReport diff --git a/limereport/items/lrchartitem.h b/limereport/items/lrchartitem.h index ff855c4..e524fb2 100644 --- a/limereport/items/lrchartitem.h +++ b/limereport/items/lrchartitem.h @@ -144,10 +144,11 @@ class ChartItem : public LimeReport::ItemDesignIntf Q_PROPERTY(bool drawPoints READ drawPoints WRITE setDrawPoints) Q_PROPERTY(int seriesLineWidth READ seriesLineWidth WRITE setSeriesLineWidth) Q_PROPERTY(bool horizontalAxisOnTop READ horizontalAxisOnTop WRITE setHorizontalAxisOnTop) - Q_PROPERTY(QString xAxisField READ xAxisField WRITE setXAxisField) - //girdChart - // TODO_ES add grid property for showing lines inside + //gridChart + Q_FLAGS(GridChartLines) + Q_PROPERTY(QString xAxisField READ xAxisField WRITE setXAxisField) + Q_PROPERTY(GridChartLines gridChartLines READ gridChartLines WRITE setGridChartLines) friend class AbstractChart; public: @@ -155,15 +156,24 @@ public: enum LegendStyle{LegendPoints, LegendLines}; enum TitleAlign{TitleAlignLeft, TitleAlignCenter, TitleAlignRight}; enum ChartType{Pie, VerticalBar, HorizontalBar, Lines, GridLines}; + enum LineType { + NoLine = 0, + HorizontalLine = 1, + VerticalLine = 2, + AllLines = 3 + }; #if QT_VERSION >= 0x050500 Q_ENUM(LegendAlign) Q_ENUM(TitleAlign) Q_ENUM(ChartType) + Q_ENUM(LineType) #else Q_ENUMS(LegendAlign) Q_ENUMS(TitleAlign) Q_ENUMS(ChartType) + Q_ENUMS(LineType) #endif + Q_DECLARE_FLAGS(GridChartLines, LineType) ChartItem(QObject* owner, QGraphicsItem* parent); ~ChartItem(); @@ -213,6 +223,9 @@ public: bool horizontalAxisOnTop() const; void setHorizontalAxisOnTop(bool horizontalAxisOnTop); + GridChartLines gridChartLines() const; + void setGridChartLines(GridChartLines flags); + protected: void paintChartTitle(QPainter* painter, QRectF titleRect); virtual BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent); @@ -243,6 +256,7 @@ private: int m_seriesLineWidth; QString m_xAxisField; bool m_horizontalAxisOnTop; + GridChartLines m_gridChartLines; }; } //namespace LimeReport #endif // LRCHARTITEM_H