19 #include <KDChartBarDiagram>
20 #include <KDChartChart>
27 #include <QTextDocument>
30 class KDReports::ChartElementPrivate :
public QSharedData
34 : m_tableModel(nullptr)
46 ~ChartElementPrivate()
53 QAbstractItemModel *m_tableModel;
57 mutable KDChart::Chart *m_chart;
59 mutable bool m_deleteChart;
63 : d(new ChartElementPrivate)
65 d->m_tableModel = tableModel;
69 : d(new ChartElementPrivate)
71 if (!modelKey.isEmpty())
76 : d(new ChartElementPrivate)
78 d->m_tableModel =
nullptr;
83 qWarning(
"ChartElement: cannot use chart, KD Reports was compiled without KD Chart support");
109 if (d->m_deleteChart)
112 d->m_deleteChart =
false;
120 d->m_size = QSizeF(width, height);
127 if (!d->m_tableModel && !d->m_chart)
130 if (!d->m_tableModel)
137 d->m_chart =
new KDChart::Chart;
138 d->m_deleteChart =
true;
141 if (d->m_chart->coordinatePlane()->diagram() == 0) {
142 KDChart::BarDiagram *diagram =
new KDChart::BarDiagram();
143 diagram->setModel(d->m_tableModel);
144 d->m_chart->coordinatePlane()->replaceDiagram(diagram);
148 KDChart::Serializer serializer( d->m_chart, d->m_tableModel );
149 QFile file(
"testSettings.xml");
150 if ( file.open( QIODevice::ReadOnly ) ) {
151 if ( serializer.read( &file ) ) {
152 qDebug() <<
"Success loading XML for chart";
157 QTextCursor &cursor = builder.
cursor();
160 fmt.setObjectType(ChartTextObject::ChartObjectTextFormat);
161 fmt.setProperty(ChartTextObject::Size, d->m_size);
163 fmt.setProperty(ChartTextObject::ChartObject, QVariant::fromValue(d->m_chart));
165 cursor.insertText(QString(QChar::ObjectReplacementCharacter), fmt);
169 qWarning(
"ChartElement: cannot create chart, KD Reports was compiled without KD Chart support");
190 if (!modelKey.isEmpty())
196 d->m_tableModel = tableModel;
ChartElement & operator=(const ChartElement &other)
ChartElement(QAbstractItemModel *tableModel)
void setChart(KDChart::Chart *chart)
Element * clone() const override
void setTableModel(QAbstractItemModel *tableModel)
void build(ReportBuilder &) const override
void setSize(qreal width, qreal height, Unit unit=Millimeters)
void setModelKey(const QString &modelKey)
Element & operator=(const Element &other)
@ Millimeters
Millimeters (the default)
QAbstractItemModel * modelForKey(const QString &key)