25 #include <KDChartBarDiagram>
26 #include <KDChartChart>
33 #include <QTextDocument>
36 class KDReports::ChartElementPrivate :
public QSharedData
40 : m_tableModel(nullptr)
52 ~ChartElementPrivate()
59 QAbstractItemModel *m_tableModel;
63 mutable KDChart::Chart *m_chart;
65 mutable bool m_deleteChart;
69 : d(new ChartElementPrivate)
71 d->m_tableModel = tableModel;
75 : d(new ChartElementPrivate)
77 if (!modelKey.isEmpty())
82 : d(new ChartElementPrivate)
84 d->m_tableModel =
nullptr;
89 qWarning(
"ChartElement: cannot use chart, KD Reports was compiled without KD Chart support");
113 if (d->m_deleteChart)
116 d->m_deleteChart =
false;
124 d->m_size = QSizeF(width, height);
131 if (!d->m_tableModel && !d->m_chart)
134 if (!d->m_tableModel)
141 d->m_chart =
new KDChart::Chart;
142 d->m_deleteChart =
true;
145 if (d->m_chart->coordinatePlane()->diagram() == 0) {
146 KDChart::BarDiagram *diagram =
new KDChart::BarDiagram();
147 diagram->setModel(d->m_tableModel);
148 d->m_chart->coordinatePlane()->replaceDiagram(diagram);
151 #if 0 // TODO, but not here...
152 KDChart::Serializer serializer( d->m_chart, d->m_tableModel );
153 QFile file(
"testSettings.xml");
154 if ( file.open( QIODevice::ReadOnly ) ) {
155 if ( serializer.read( &file ) ) {
156 qDebug() <<
"Success loading XML for chart";
161 QTextCursor &cursor = builder.
cursor();
164 fmt.setObjectType(ChartTextObject::ChartObjectTextFormat);
165 fmt.setProperty(ChartTextObject::Size, d->m_size);
167 fmt.setProperty(ChartTextObject::ChartObject, QVariant::fromValue(d->m_chart));
169 cursor.insertText(QString(QChar::ObjectReplacementCharacter), fmt);
173 qWarning(
"ChartElement: cannot create chart, KD Reports was compiled without KD Chart support");
194 if (!modelKey.isEmpty())
200 d->m_tableModel = tableModel;