0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00

ChartItem has been fixed

This commit is contained in:
Arin Alexander 2020-04-06 19:48:16 +03:00
parent e3d4691c0f
commit a7db5d51bc
4 changed files with 39 additions and 8 deletions

View File

@ -133,7 +133,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc
LIMEREPORT_VERSION_MAJOR = 1
LIMEREPORT_VERSION_MINOR = 5
LIMEREPORT_VERSION_RELEASE = 45
LIMEREPORT_VERSION_RELEASE = 46
LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}'
DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\"

View File

@ -129,7 +129,8 @@ void SeriesItem::setPreferredType(const SeriesItemPreferredType& type)
ChartItem::ChartItem(QObject *owner, QGraphicsItem *parent)
: ItemDesignIntf(xmlTag, owner, parent), m_legendBorder(true),
m_legendAlign(LegendAlignCenter), m_titleAlign(TitleAlignCenter),
m_chartType(Pie), m_labelsField("")
m_chartType(Pie), m_labelsField(""), m_isEmpty(true),
m_showLegend(true)
{
m_labels<<"First"<<"Second"<<"Thrid";
m_chart = new PieChart(this);
@ -176,12 +177,15 @@ void ChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
(maxTitleHeight)):0;
QRectF titleRect = QRectF(borderMargin,borderMargin,rect().width()-borderMargin*2,titleOffset);
QRectF legendRect = m_chart->calcChartLegendRect(painter->font(), rect(), false, borderMargin, titleOffset);
QRectF legendRect = QRectF(0,0,0,0);
if (m_showLegend)
legendRect = m_chart->calcChartLegendRect(painter->font(), rect(), false, borderMargin, titleOffset);
QRectF diagramRect = rect().adjusted(borderMargin,titleOffset+borderMargin,
-(legendRect.width()+borderMargin*2),-borderMargin);
paintChartTitle(painter, titleRect);
m_chart->paintChartLegend(painter,legendRect);
if (m_showLegend)
m_chart->paintChartLegend(painter,legendRect);
m_chart->paintChart(painter,diagramRect);
painter->restore();
@ -224,11 +228,15 @@ QObject *ChartItem::elementAt(const QString &collectionName, int index)
void ChartItem::updateItemSize(DataSourceManager *dataManager, RenderPass , int )
{
m_isEmpty = false;
if (dataManager && dataManager->dataSource(m_datasource)){
IDataSource* ds = dataManager->dataSource(m_datasource);
foreach (SeriesItem* series, m_series) {
series->setLabelsColumn(m_labelsField);
series->fillSeriesData(ds);
if (series->isEmpty()){
series->setLabelsColumn(m_labelsField);
series->fillSeriesData(ds);
}
}
fillLabels(ds);
}
@ -258,7 +266,22 @@ QWidget *ChartItem::defaultEditor()
bool ChartItem::isNeedUpdateSize(RenderPass pass) const
{
return pass == FirstPass;
return pass == FirstPass && m_isEmpty;
}
bool ChartItem::showLegend() const
{
return m_showLegend;
}
void ChartItem::setShowLegend(bool showLegend)
{
if (m_showLegend != showLegend){
m_showLegend = showLegend;
notify("showLegend", !m_showLegend, m_showLegend);
update();
}
m_showLegend = showLegend;
}
QList<QString> ChartItem::labels() const

View File

@ -52,6 +52,7 @@ public:
void setColor(const QColor &color);
SeriesItemPreferredType preferredType() const;
void setPreferredType(const SeriesItemPreferredType& preferredType);
bool isEmpty(){ return m_data.values().isEmpty();}
private:
QString m_name;
QString m_valuesColumn;
@ -127,6 +128,7 @@ class ChartItem : public LimeReport::ItemDesignIntf
Q_PROPERTY(TitleAlign titleAlign READ titleAlign WRITE setTitleAlign)
Q_PROPERTY(ChartType chartType READ chartType WRITE setChartType)
Q_PROPERTY(QString labelsField READ labelsField WRITE setLabelsField)
Q_PROPERTY(bool showLegend READ showLegend WRITE setShowLegend)
friend class AbstractChart;
public:
@ -176,6 +178,9 @@ public:
void setLabels(const QList<QString> &labels);
QWidget* defaultEditor();
bool showLegend() const;
void setShowLegend(bool showLegend);
protected:
void paintChartTitle(QPainter* painter, QRectF titleRect);
virtual BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent);
@ -200,6 +205,8 @@ private:
ChartType m_chartType;
QString m_labelsField;
QList<QString> m_labels;
bool m_isEmpty;
bool m_showLegend;
};
} //namespace LimeReport

View File

@ -609,6 +609,8 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
while(!bandDatasource->eof() && !m_renderCanceled){
datasources()->updateChildrenData(dataBand->datasourceName());
BandDesignIntf* rawData = renderData(dataBand);
if (!rawData->isEmpty() || dataBand->printIfEmpty()){
@ -624,7 +626,6 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
if (dataBand->keepFooterTogether() && !bandDatasource->hasNext())
openFooterGroup(dataBand);
datasources()->updateChildrenData(dataBand->datasourceName());
m_lastDataBand = dataBand;
if (header && !firstTime && header->repeatOnEachRow())