mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-23 20:22:58 +03:00
ChartItem has been updated
This commit is contained in:
parent
af589e31ba
commit
cc0dad863e
@ -77,10 +77,9 @@ void SeriesItem::setLabelsColumn(const QString &labelsColumn)
|
||||
SeriesItem *SeriesItem::clone()
|
||||
{
|
||||
SeriesItem* result = new SeriesItem();
|
||||
result->setName(name());
|
||||
result->setLabelsColumn(labelsColumn());
|
||||
result->setValuesColumn(valuesColumn());
|
||||
result->setColor(color());
|
||||
for (int i = 0; i < this->metaObject()->propertyCount(); ++i){
|
||||
result->setProperty(this->metaObject()->property(i).name(),property(this->metaObject()->property(i).name()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -110,6 +109,16 @@ void SeriesItem::setColor(const QColor &color)
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
SeriesItem::SeriesItemPreferredType SeriesItem::preferredType() const
|
||||
{
|
||||
return m_preferredType;
|
||||
}
|
||||
|
||||
void SeriesItem::setPreferredType(const SeriesItemPreferredType& type)
|
||||
{
|
||||
m_preferredType = type;
|
||||
}
|
||||
|
||||
ChartItem::ChartItem(QObject *owner, QGraphicsItem *parent)
|
||||
: ItemDesignIntf(xmlTag, owner, parent), m_legendBorder(true),
|
||||
m_legendAlign(LegendAlignCenter), m_titleAlign(TitleAlignCenter),
|
||||
@ -665,6 +674,11 @@ void VerticalBarChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
vPadding(chartRect)+valuesVMargin(painter),
|
||||
-(hPadding(chartRect)*2),
|
||||
-(vPadding(chartRect)+barsShift) ));
|
||||
paintSerialLines(painter, chartRect.adjusted(
|
||||
hPadding(chartRect)*2+valuesHMargin(painter),
|
||||
vPadding(chartRect)+valuesVMargin(painter),
|
||||
-(hPadding(chartRect)*2),
|
||||
-(vPadding(chartRect)+barsShift) ));
|
||||
paintLabels(painter,calcRect);
|
||||
}
|
||||
|
||||
@ -692,26 +706,37 @@ void VerticalBarChart::paintVerticalGrid(QPainter *painter, QRectF gridRect)
|
||||
|
||||
void VerticalBarChart::paintVerticalBars(QPainter *painter, QRectF barsRect)
|
||||
{
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing,false);
|
||||
|
||||
int delta = int(maxValue()-minValue());
|
||||
delta = genNextValue(delta);
|
||||
|
||||
int barSeriesCount = 0;
|
||||
foreach(SeriesItem* series, m_chartItem->series()){
|
||||
if (series->preferredType() == SeriesItem::Bar) barSeriesCount++;
|
||||
}
|
||||
|
||||
barSeriesCount = (m_chartItem->itemMode()==DesignMode) ? seriesCount() : barSeriesCount;
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing,false);
|
||||
|
||||
qreal vStep = barsRect.height() / delta;
|
||||
qreal hStep = (barsRect.width() / valuesCount()) / seriesCount();
|
||||
qreal hStep = (barsRect.width() / valuesCount()) / (barSeriesCount == 0 ? 1 : barSeriesCount);
|
||||
qreal topShift = (delta - (maxValue()-minValue())) * vStep +barsRect.top();
|
||||
|
||||
if (!m_chartItem->series().isEmpty() && !m_chartItem->series().at(0)->data()->labels().isEmpty()){
|
||||
int curSeries = 0;
|
||||
foreach (SeriesItem* series, m_chartItem->series()) {
|
||||
if (series->preferredType() == SeriesItem::Bar){
|
||||
qreal curHOffset = curSeries*hStep+barsRect.left();
|
||||
painter->setBrush(series->color());
|
||||
foreach (qreal value, series->data()->values()) {
|
||||
painter->drawRect(QRectF(curHOffset, maxValue()*vStep+topShift, hStep, -value*vStep));
|
||||
curHOffset+=hStep*seriesCount();
|
||||
curHOffset+=hStep*barSeriesCount;
|
||||
}
|
||||
curSeries++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qreal curHOffset = barsRect.left();
|
||||
int curColor = 0;
|
||||
@ -726,6 +751,47 @@ void VerticalBarChart::paintVerticalBars(QPainter *painter, QRectF barsRect)
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void VerticalBarChart::paintSerialLines(QPainter* painter, QRectF barsRect)
|
||||
{
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing,true);
|
||||
int delta = int(maxValue()-minValue());
|
||||
delta = genNextValue(delta);
|
||||
|
||||
qreal vStep = barsRect.height() / delta;
|
||||
qreal hStep = (barsRect.width() / valuesCount());
|
||||
qreal topShift = (delta - (maxValue()-minValue())) * vStep +barsRect.top();
|
||||
|
||||
if (!m_chartItem->series().isEmpty() && !m_chartItem->series().at(0)->data()->labels().isEmpty()){
|
||||
int curSeries = 0;
|
||||
foreach (SeriesItem* series, m_chartItem->series()) {
|
||||
if (series->preferredType() == SeriesItem::Line){
|
||||
QPen pen(series->color());
|
||||
pen.setWidth(4);
|
||||
painter->setPen(pen);
|
||||
for (int i = 0; i < series->data()->values().count()-1; ++i ){
|
||||
QPoint startPoint = QPoint((i+1)*hStep + barsRect.left()-hStep/2,
|
||||
(maxValue()*vStep+topShift) - series->data()->values().at(i)*vStep
|
||||
);
|
||||
QPoint endPoint = QPoint((i+2)*hStep + barsRect.left()-hStep/2,
|
||||
(maxValue()*vStep+topShift) - series->data()->values().at(i+1)*vStep
|
||||
);
|
||||
painter->drawLine(startPoint, endPoint);
|
||||
QRect startPointRect(startPoint,startPoint);
|
||||
QRect endPointRect(endPoint,endPoint);
|
||||
int radius = 4;
|
||||
painter->setBrush(series->color());
|
||||
painter->drawEllipse(startPointRect.adjusted(radius,radius,-radius,-radius));
|
||||
painter->drawEllipse(endPointRect.adjusted(radius,radius,-radius,-radius));
|
||||
|
||||
}
|
||||
}
|
||||
curSeries++;
|
||||
}
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void VerticalBarChart::paintLabels(QPainter *painter, QRectF labelsRect)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef LRCHARTITEM_H
|
||||
#define LRCHARTITEM_H
|
||||
#include "lritemdesignintf.h"
|
||||
#include "lrglobal.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
@ -27,8 +28,11 @@ class SeriesItem : public QObject{
|
||||
Q_PROPERTY(QString valuesColumn READ valuesColumn WRITE setValuesColumn )
|
||||
Q_PROPERTY(QString labelsColumn READ labelsColumn WRITE setLabelsColumn )
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor)
|
||||
Q_PROPERTY(SeriesItemPreferredType preferredType READ preferredType WRITE setPreferredType)
|
||||
Q_ENUMS(SeriesItemPreferredType)
|
||||
public:
|
||||
SeriesItem(QObject* parent = 0):QObject(parent){}
|
||||
enum SeriesItemPreferredType {Bar, Line};
|
||||
SeriesItem(QObject* parent = 0) : QObject(parent), m_preferredType(Bar){}
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
QString valuesColumn() const;
|
||||
@ -40,12 +44,15 @@ public:
|
||||
SeriesItemData* data(){ return &m_data;}
|
||||
QColor color() const;
|
||||
void setColor(const QColor &color);
|
||||
SeriesItemPreferredType preferredType() const;
|
||||
void setPreferredType(const SeriesItemPreferredType& preferredType);
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_valuesColumn;
|
||||
QString m_labelsColumn;
|
||||
SeriesItemData m_data;
|
||||
QColor m_color;
|
||||
SeriesItemPreferredType m_preferredType;
|
||||
};
|
||||
|
||||
class ChartItem;
|
||||
@ -121,6 +128,7 @@ public:
|
||||
void paintChart(QPainter *painter, QRectF chartRect);
|
||||
void paintVerticalGrid(QPainter *painter, QRectF gridRect);
|
||||
void paintVerticalBars(QPainter *painter, QRectF barsRect);
|
||||
void paintSerialLines(QPainter *painter, QRectF barsRect);
|
||||
void paintLabels(QPainter *painter, QRectF labelsRect);
|
||||
};
|
||||
|
||||
|
@ -22,7 +22,6 @@ ChartItemEditor::ChartItemEditor(LimeReport::ChartItem *item, LimeReport::PageDe
|
||||
colorLayout->insertStretch(0);
|
||||
readSetting();
|
||||
init();
|
||||
|
||||
connect(m_colorButton, SIGNAL(clicked(bool)), this, SLOT(slotChangeSeriesColor()));
|
||||
}
|
||||
|
||||
@ -112,6 +111,13 @@ void ChartItemEditor::init()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int enumIndex = LimeReport::SeriesItem::staticMetaObject.indexOfEnumerator("SeriesItemPreferredType");
|
||||
QMetaEnum enumerator = LimeReport::SeriesItem::staticMetaObject.enumerator(enumIndex);
|
||||
for (int i = 0; i<enumerator.keyCount(); ++i){
|
||||
ui->seriesTypeComboBox->addItem(enumerator.key(i));
|
||||
}
|
||||
|
||||
ui->labelsFieldComboBox->setCurrentText(m_charItem->labelsField());
|
||||
if (!m_charItem->series().isEmpty()){
|
||||
enableSeriesEditor();
|
||||
@ -127,6 +133,7 @@ void ChartItemEditor::enableSeriesEditor()
|
||||
{
|
||||
ui->seriesNameLineEdit->setEnabled(true);
|
||||
ui->valuesFieldComboBox->setEnabled(true);
|
||||
ui->seriesTypeComboBox->setEnabled(true);
|
||||
m_colorButton->setEnabled(true);
|
||||
m_colorIndicator->setEnabled(true);
|
||||
}
|
||||
@ -139,6 +146,7 @@ void ChartItemEditor::disableSeriesEditor()
|
||||
m_colorButton->setDisabled(true);
|
||||
m_colorIndicator->setDisabled(true);
|
||||
ui->valuesFieldComboBox->setCurrentText("");
|
||||
ui->seriesTypeComboBox->setDisabled(true);
|
||||
}
|
||||
|
||||
LimeReport::SeriesItem *ChartItemEditor::currentSeries()
|
||||
@ -214,6 +222,9 @@ void ChartItemEditor::on_tableWidget_itemSelectionChanged()
|
||||
ui->seriesNameLineEdit->setText(series->name());
|
||||
ui->valuesFieldComboBox->setCurrentText(series->valuesColumn());
|
||||
m_colorIndicator->setColor(series->color());
|
||||
static int enumIndex = LimeReport::SeriesItem::staticMetaObject.indexOfEnumerator("SeriesItemPreferredType");
|
||||
QMetaEnum enumerator = LimeReport::SeriesItem::staticMetaObject.enumerator(enumIndex);
|
||||
ui->seriesTypeComboBox->setCurrentText(enumerator.valueToKey(series->preferredType()));
|
||||
enableSeriesEditor();
|
||||
}
|
||||
}
|
||||
@ -247,3 +258,12 @@ void ChartItemEditor::slotChangeSeriesColor()
|
||||
m_colorIndicator->setColor(colorDialog.selectedColor());
|
||||
}
|
||||
}
|
||||
|
||||
void ChartItemEditor::on_seriesTypeComboBox_currentIndexChanged(const QString &arg1)
|
||||
{
|
||||
static int enumIndex = LimeReport::SeriesItem::staticMetaObject.indexOfEnumerator("SeriesItemPreferredType");
|
||||
QMetaEnum enumerator = LimeReport::SeriesItem::staticMetaObject.enumerator(enumIndex);
|
||||
if (currentSeries()){
|
||||
currentSeries()->setPreferredType(static_cast<LimeReport::SeriesItem::SeriesItemPreferredType>(enumerator.keysToValue(arg1.toLatin1())));
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ private slots:
|
||||
void on_valuesFieldComboBox_currentTextChanged(const QString &arg1);
|
||||
void on_labelsFieldComboBox_currentTextChanged(const QString &arg1);
|
||||
void slotChangeSeriesColor();
|
||||
void on_seriesTypeComboBox_currentIndexChanged(const QString &arg1);
|
||||
|
||||
private:
|
||||
void readSetting();
|
||||
void writeSetting();
|
||||
|
@ -110,6 +110,16 @@
|
||||
<item row="2" column="1">
|
||||
<widget class="QWidget" name="colorWidget" native="true"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="seriesTypeComboBox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "lrcolorindicator.h"
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
||||
void ColorIndicator::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
@ -7,8 +8,19 @@ void ColorIndicator::paintEvent(QPaintEvent* event)
|
||||
painter.save();
|
||||
painter.setBrush(m_color);
|
||||
painter.setPen(Qt::gray);
|
||||
QRect rect = event->rect().adjusted(3,3,-4,-4);
|
||||
|
||||
QRect rect = event->rect().adjusted(3,3,-3,-3);
|
||||
|
||||
if (rect.height() < rect.width()){
|
||||
qreal offset = (rect.width()-rect.height()) / 2;
|
||||
rect.setWidth(rect.height());
|
||||
rect.adjust(offset,0,offset,0);
|
||||
} else {
|
||||
qreal offset = (rect.height()-rect.width()) / 2;
|
||||
rect.setHeight(rect.width());
|
||||
rect.adjust(0,offset,0,offset);
|
||||
}
|
||||
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.drawEllipse(rect);
|
||||
painter.restore();
|
||||
|
Loading…
Reference in New Issue
Block a user