[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/kexi/plugins/reportspgz/backend
From: Adam Pigg <adam () piggz ! co ! uk>
Date: 2008-10-17 21:49:28
Message-ID: 1224280168.347457.5996.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 872711 by piggz:
Added ability to link data from a chart, to data in the report, e.g. in msa child \
forms/reports and charts. This makes it possible to have a slightly different chart \
in each section of a report, based on the main data in that section. See \
http://www.piggz.co.uk/LinkedChart.pdf for a sample.
CCMAIL: kexi-devel@kde.org
M +47 -9 common/krchartdata.cpp
M +24 -5 common/krchartdata.h
M +7 -0 renderer/orprerender.cpp
M +10 -0 wrtembed/reportentitychart.cpp
--- trunk/koffice/kexi/plugins/reportspgz/backend/common/krchartdata.cpp \
#872710:872711 @@ -34,6 +34,9 @@
#include <kexidb/connection.h>
#include <kexidb/cursor.h>
#include <kexidb/parser/parser.h>
+#include <kexidb/field.h>
+#include <kexidb/queryschema.h>
+
#include <koproperty/property.h>
#include <QMotifStyle>
#include <kdebug.h>
@@ -107,6 +110,10 @@
// _lnColor->setValue(ls.lnColor);
// _lnStyle->setValue(ls.style);
// }
+ } else if (n =="linkmaster") {
+ _linkMaster->setValue(node.firstChild().nodeValue());
+ } else if (n =="linkchild") {
+ _linkChild->setValue(node.firstChild().nodeValue());
} else {
kDebug() << "while parsing field element encountered unknow element: " \
<< n; }
@@ -164,6 +171,8 @@
_bgColor = new KoProperty::Property("BackgroundColor", Qt::white, "Background \
Color", "Background Color");
+ _linkMaster = new KoProperty::Property("LinkMaster", "", "Link Master", \
i18n("Fields from master data source")); + _linkChild = new \
KoProperty::Property("LinkChild", "", "Link Child", i18n("Fields from child data \
source"));
_set->addProperty(_name);
_set->addProperty(_dataSource);
@@ -180,10 +189,9 @@
_set->addProperty(_yTitle);
_set->addProperty(_bgColor);
_set->addProperty(_displayLegend);
+ _set->addProperty ( _linkMaster );
+ _set->addProperty ( _linkChild );
- //_set->addProperty ( _lnColor );
- //_set->addProperty ( _lnStyle );
-
set3D(false);
setAA(false);
setColorScheme("default");
@@ -303,6 +311,17 @@
}
}
+QStringList KRChartData::masterFields()
+{
+ return _linkMaster->value().toString().split(",");
+}
+
+void KRChartData::setLinkData(QString fld, QVariant val)
+{
+ kDebug() << "Field: " << fld << "is" << val;
+ _links[fld] = val;
+}
+
QStringList KRChartData::fieldNames(const QString &stmt)
{
KexiDB::Parser *pars;
@@ -334,7 +353,6 @@
{
QStringList fn;
QString ds = _dataSource->value().toString();
- KexiDB::Cursor *c = 0;
KexiDB::Field::List fl;
QString s;
@@ -372,8 +390,6 @@
}
}
-
-
if (!xAxis) {
xAxis = new \
KDChart::CartesianAxis(dynamic_cast<KDChart::AbstractCartesianDiagram*>(_chartWidget->diagram()));
xAxis->setPosition(KDChart::CartesianAxis::Bottom);
@@ -395,18 +411,40 @@
{
QString ds = _dataSource->value().toString();
KexiDB::Cursor *c = 0;
+ KexiDB::QuerySchema *qs;
+ //Determin the type of the source data and create a queryschema
if (_conn && _conn->tableSchema(ds)) {
kDebug() << ds << "is a table";
- c = _conn->executeQuery(* (_conn->tableSchema(ds)), 1);
+ qs = new KexiDB::QuerySchema(*(_conn->tableSchema(ds)));
} else if (_conn && _conn->querySchema(ds)) {
kDebug() << ds << "is a query";
- c = _conn->executeQuery(* (_conn->querySchema(ds)), 1);
+ qs = _conn->querySchema(ds);
} else {
kDebug() << ds << "is a statement";
- c = _conn->executeQuery(ds);
+ KexiDB::Parser *pars;
+ pars = new KexiDB::Parser(_conn);
+ pars->setOperation(KexiDB::Parser::OP_Select);
+ pars->parse(ds);
+ qs = pars->select();
}
+ //Now go through each master field value, and add the correspanding child field
+ //as a where condition on the query
+ if (qs) {
+ QStringList childFields = _linkChild->value().toString().split(",");
+ QStringList masterFields = _linkMaster->value().toString().split(",");
+
+ for(int i = 0; i < childFields.size(); ++i){
+ KexiDB::Field *f = qs->findTableField(childFields[i]);
+ //Only add the condition if we found the child field, and we have data \
for the master field + if (f && _links.contains(masterFields[i])) {
+ qs->addToWhereExpression(f, _links[masterFields[i]]);
+ }
+ }
+
+ c = _conn->executeQuery(*qs, 1);
+ }
return c;
}
void KRChartData::setBackgroundColor(const QColor&)
--- trunk/koffice/kexi/plugins/reportspgz/backend/common/krchartdata.h #872710:872711
@@ -32,6 +32,7 @@
{
class Connection;
class Cursor;
+class Field;
}
/**
@@ -56,8 +57,27 @@
KDChart::Widget *widget() {
return _chartWidget;
}
+
+ /**
+ @brief Perform the query for the chart and set the charts data
+ */
void populateData();
void setConnection(KexiDB::Connection*);
+
+ /**
+ @brief Set the value of a field from the master (report) data set
+ This data will be used when retrieving the data for the chart
+ as the values in a 'where' clause.
+ */
+ void setLinkData(QString, QVariant);
+
+ /**
+ @brief Return the list of master fields
+ The caller will use this to set the current value for each field
+ at that stage in the report
+ */
+ QStringList masterFields();
+
protected:
KRSize _size;
KoProperty::Property * _dataSource;
@@ -73,11 +93,9 @@
KoProperty::Property *_bgColor;
KoProperty::Property* _displayLegend;
- //KoProperty::Property* _lnWeight;
- //KoProperty::Property* _lnStyle;
+ KoProperty::Property* _linkMaster;
+ KoProperty::Property* _linkChild;
- //ORLineStyleData lineStyle();
-
KDChart::Widget *_chartWidget;
void set3D(bool);
@@ -90,7 +108,6 @@
QStringList fieldNames(const QString &);
QStringList fieldNamesHackUntilImprovedParser(const QString &);
-
private:
virtual void createProperties();
static int RTTI;
@@ -101,6 +118,8 @@
KexiDB::Cursor *dataSet();
+ QMap<QString,QVariant> _links; //Map of field->value for child/master links
+
};
#endif
--- trunk/koffice/kexi/plugins/reportspgz/backend/renderer/orprerender.cpp \
#872710:872711 @@ -792,6 +792,13 @@
} else if (elemThis->type() == KRObjectData::EntityChart) {
KRChartData * ch = elemThis->toChart();
ch->setConnection(_conn);
+
+ QStringList masterFields = ch->masterFields();
+ for (int i = 0; i < masterFields.size(); ++i){
+ if (!masterFields[i].simplified().isEmpty()){
+ ch->setLinkData(masterFields[i], \
_query->getQuery()->value(_query->fieldNumber(masterFields[i]))); + }
+ }
ch->populateData();
if (ch->widget()) {
OROPicture * id = new OROPicture();
--- trunk/koffice/kexi/plugins/reportspgz/backend/wrtembed/reportentitychart.cpp \
#872710:872711 @@ -197,6 +197,16 @@
QDomElement dl = doc.createElement("displaylegend");
dl.appendChild(doc.createTextNode(_displayLegend->value().toBool() ? "true" : \
"false")); entity.appendChild(dl);
+
+ //link master/child
+ QDomElement lm = doc.createElement("linkmaster");
+ lm.appendChild(doc.createTextNode(_linkMaster->value().toString()));
+ entity.appendChild(lm);
+ QDomElement lc = doc.createElement("linkchild");
+ lc.appendChild(doc.createTextNode(_linkChild->value().toString()));
+ entity.appendChild(lc);
+
+
//Line Style
// buildXMLLineStyle(doc, entity, lineStyle());
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic