diff --git a/src/plugins/reports/kexidbreportdata.cpp b/src/plugins/reports/kexidbreportdata.cpp
index 7b5ba9ebc..b410968ef 100644
--- a/src/plugins/reports/kexidbreportdata.cpp
+++ b/src/plugins/reports/kexidbreportdata.cpp
@@ -1,416 +1,420 @@
/*
* Kexi Report Plugin
* Copyright (C) 2007-2009 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "kexidbreportdata.h"
#include
#include
#include
#include
#include
#include
#include
class Q_DECL_HIDDEN KexiDBReportData::Private
{
public:
explicit Private(KDbConnection *pDb)
: cursor(0), connection(pDb), originalSchema(0), copySchema(0)
{
}
~Private()
{
delete copySchema;
delete originalSchema;
}
QString objectName;
KDbCursor *cursor;
KDbConnection *connection;
KDbQuerySchema *originalSchema;
KDbQuerySchema *copySchema;
};
KexiDBReportData::KexiDBReportData (const QString &objectName,
KDbConnection * pDb)
: d(new Private(pDb))
{
d->objectName = objectName;
getSchema();
}
KexiDBReportData::KexiDBReportData(const QString& objectName,
const QString& pluginId,
KDbConnection* pDb)
: d(new Private(pDb))
{
d->objectName = objectName;
getSchema(pluginId);
}
void KexiDBReportData::setSorting(const QList& sorting)
{
if (d->copySchema) {
if (sorting.isEmpty())
return;
KDbOrderByColumnList order;
for (int i = 0; i < sorting.count(); i++) {
if (!order.appendField(d->copySchema, sorting[i].field(),
KDbOrderByColumn::fromQt(sorting[i].order())))
{
qWarning() << "Cannot set sort field" << i << sorting[i].field();
return;
}
}
d->copySchema->setOrderByColumnList(order);
} else {
qWarning() << "Unable to sort null schema";
}
}
-void KexiDBReportData::addExpression(const QString& field, const QVariant& value, char relation)
+void KexiDBReportData::addCondition(const QString &field, const QVariant &value, const QString& relation)
{
if (d->copySchema) {
KDbField *fld = d->copySchema->findTableField(field);
if (fld) {
- d->copySchema->addToWhereExpression(fld, value, KDbToken(relation));
+ if (relation.length() == 1) {
+ d->copySchema->addToWhereExpression(fld, value, KDbToken(relation.toLatin1()[0]));
+ } else {
+ qWarning() << "Invalid relation passed in:" << relation;
+ }
}
} else {
qDebug() << "Unable to add expresstion to null schema";
}
}
KexiDBReportData::~KexiDBReportData()
{
close();
delete d;
}
bool KexiDBReportData::open()
{
if ( d->connection && d->cursor == 0 )
{
if ( d->objectName.isEmpty() )
{
return false;
}
else if ( d->copySchema)
{
qDebug() << "Opening cursor.." << *d->copySchema;
d->cursor = d->connection->executeQuery ( d->copySchema, 1 );
}
if ( d->cursor )
{
qDebug() << "Moving to first record..";
return d->cursor->moveFirst();
}
else
return false;
}
return false;
}
bool KexiDBReportData::close()
{
if (d->cursor) {
const bool ok = d->cursor->close();
d->connection->deleteCursor(d->cursor);
d->cursor = nullptr;
return ok;
}
return true;
}
bool KexiDBReportData::getSchema(const QString& pluginId)
{
if (d->connection)
{
delete d->originalSchema;
d->originalSchema = 0;
delete d->copySchema;
d->copySchema = 0;
if ((pluginId.isEmpty() || pluginId == "org.kexi-project.table")
&& d->connection->tableSchema(d->objectName))
{
qDebug() << d->objectName << "is a table..";
d->originalSchema = new KDbQuerySchema(d->connection->tableSchema(d->objectName));
}
else if ((pluginId.isEmpty() || pluginId == "org.kexi-project.query")
&& d->connection->querySchema(d->objectName))
{
qDebug() << d->objectName << "is a query..";
qDebug() << *d->connection->querySchema(d->objectName);
d->originalSchema = new KDbQuerySchema(*(d->connection->querySchema(d->objectName)));
}
if (d->originalSchema) {
const KDbNativeStatementBuilder builder(d->connection);
KDbEscapedString sql;
if (builder.generateSelectStatement(&sql, d->originalSchema)) {
qDebug() << "Original:" << sql;
} else {
qDebug() << "Original: ERROR";
}
qDebug() << *d->originalSchema;
d->copySchema = new KDbQuerySchema(*d->originalSchema);
qDebug() << *d->copySchema;
if (builder.generateSelectStatement(&sql, d->copySchema)) {
qDebug() << "Copy:" << sql;
} else {
qDebug() << "Copy: ERROR";
}
}
return true;
}
return false;
}
QString KexiDBReportData::sourceName() const
{
return d->objectName;
}
int KexiDBReportData::fieldNumber ( const QString &fld ) const
{
if (!d->cursor || !d->cursor->query()) {
return -1;
}
const KDbQueryColumnInfo::Vector fieldsExpanded(
d->cursor->query()->fieldsExpanded(KDbQuerySchema::Unique));
for (int i = 0; i < fieldsExpanded.size() ; ++i) {
if (0 == QString::compare(fld, fieldsExpanded[i]->aliasOrName(), Qt::CaseInsensitive)) {
return i;
}
}
return -1;
}
QStringList KexiDBReportData::fieldNames() const
{
if (!d->originalSchema) {
return QStringList();
}
QStringList names;
const KDbQueryColumnInfo::Vector fieldsExpanded(
d->originalSchema->fieldsExpanded(KDbQuerySchema::Unique));
for (int i = 0; i < fieldsExpanded.size(); i++) {
//! @todo in some Kexi mode captionOrAliasOrName() would be used here (more user-friendly)
names.append(fieldsExpanded[i]->aliasOrName());
}
return names;
}
-QVariant KexiDBReportData::value ( unsigned int i ) const
+QVariant KexiDBReportData::value (int i) const
{
if ( d->cursor )
return d->cursor->value ( i );
return QVariant();
}
QVariant KexiDBReportData::value ( const QString &fld ) const
{
int i = fieldNumber ( fld );
if (d->cursor && i >= 0)
return d->cursor->value ( i );
return QVariant();
}
bool KexiDBReportData::moveNext()
{
if ( d->cursor )
return d->cursor->moveNext();
return false;
}
bool KexiDBReportData::movePrevious()
{
if ( d->cursor ) return d->cursor->movePrev();
return false;
}
bool KexiDBReportData::moveFirst()
{
if ( d->cursor ) return d->cursor->moveFirst();
return false;
}
bool KexiDBReportData::moveLast()
{
if ( d->cursor )
return d->cursor->moveLast();
return false;
}
qint64 KexiDBReportData::at() const
{
if ( d->cursor )
return d->cursor->at();
return 0;
}
qint64 KexiDBReportData::recordCount() const
{
if ( d->copySchema )
{
return KDb::recordCount ( d->copySchema );
}
return 1;
}
static bool isInterpreterSupported(const QString &interpreterName)
{
return 0 == interpreterName.compare(QLatin1String("javascript"), Qt::CaseInsensitive)
|| 0 == interpreterName.compare(QLatin1String("qtscript"), Qt::CaseInsensitive);
}
QStringList KexiDBReportData::scriptList() const
{
QStringList scripts;
if( d->connection) {
QList scriptids = d->connection->objectIds(KexiPart::ScriptObjectType);
QStringList scriptnames = d->connection->objectNames(KexiPart::ScriptObjectType);
qDebug() << scriptids << scriptnames;
//A blank entry
scripts << "";
int i = 0;
foreach(int id, scriptids) {
qDebug() << "ID:" << id;
tristate res;
QString script;
res = d->connection->loadDataBlock(id, &script, QString());
if (res == true) {
QDomDocument domdoc;
bool parsed = domdoc.setContent(script, false);
QDomElement scriptelem = domdoc.namedItem("script").toElement();
if (parsed && !scriptelem.isNull()) {
if (scriptelem.attribute("scripttype") == "object"
&& isInterpreterSupported(scriptelem.attribute("language")))
{
scripts << scriptnames[i];
}
} else {
qDebug() << "Unable to parse script";
}
} else {
qDebug() << "Unable to loadDataBlock";
}
++i;
}
qDebug() << scripts;
}
return scripts;
}
QString KexiDBReportData::scriptCode(const QString& scriptname) const
{
QString scripts;
if (d->connection) {
QList scriptids = d->connection->objectIds(KexiPart::ScriptObjectType);
QStringList scriptnames = d->connection->objectNames(KexiPart::ScriptObjectType);
int i = 0;
foreach(int id, scriptids) {
qDebug() << "ID:" << id;
tristate res;
QString script;
res = d->connection->loadDataBlock(id, &script, QString());
if (res == true) {
QDomDocument domdoc;
bool parsed = domdoc.setContent(script, false);
if (! parsed) {
qDebug() << "XML parsing error";
return QString();
}
QDomElement scriptelem = domdoc.namedItem("script").toElement();
if (scriptelem.isNull()) {
qDebug() << "script domelement is null";
return QString();
}
QString interpretername = scriptelem.attribute("language");
qDebug() << scriptelem.attribute("scripttype");
qDebug() << scriptname << scriptnames[i];
if ((isInterpreterSupported(interpretername) && scriptelem.attribute("scripttype") == "module")
|| scriptname == scriptnames[i])
{
scripts += '\n' + scriptelem.text().toUtf8();
}
++i;
} else {
qDebug() << "Unable to loadDataBlock";
}
}
}
return scripts;
}
-QStringList KexiDBReportData::dataSources() const
+QStringList KexiDBReportData::dataSourceNames() const
{
//Get the list of queries in the database
QStringList qs;
if (d->connection && d->connection->isConnected()) {
QList tids = d->connection->tableIds();
qs << "";
for (int i = 0; i < tids.size(); ++i) {
KDbTableSchema* tsc = d->connection->tableSchema(tids[i]);
if (tsc)
qs << tsc->name();
}
QList qids = d->connection->queryIds();
qs << "";
for (int i = 0; i < qids.size(); ++i) {
KDbQuerySchema* qsc = d->connection->querySchema(qids[i]);
if (qsc)
qs << qsc->name();
}
}
return qs;
}
-KReportData* KexiDBReportData::create(const QString& source) const
+KReportDataSource* KexiDBReportData::create(const QString& source) const
{
return new KexiDBReportData(source, d->connection);
}
diff --git a/src/plugins/reports/kexidbreportdata.h b/src/plugins/reports/kexidbreportdata.h
index 5dc9f2907..013ac0956 100644
--- a/src/plugins/reports/kexidbreportdata.h
+++ b/src/plugins/reports/kexidbreportdata.h
@@ -1,82 +1,82 @@
/*
* Kexi Report Plugin
* Copyright (C) 2007-2009 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef __KEXIDBREPORTDATA_H__
#define __KEXIDBREPORTDATA_H__
#include
#include
#include
#include
#include
-#include
+#include
/**
*/
-class KexiDBReportData : public KReportData
+class KexiDBReportData : public KReportDataSource
{
public:
KexiDBReportData(const QString &objectName, KDbConnection *conn);
/*!
* @a pluginId specifies type of @a objectName, a table or query.
* Types accepted:
* -"org.kexi-project.table"
* -"org.kexi-project.query"
* -empty QString() - attempt to resolve @a objectName
*/
KexiDBReportData(const QString &objectName, const QString& pluginId, KDbConnection *conn);
virtual ~KexiDBReportData();
virtual QStringList fieldNames() const;
virtual void setSorting(const QList& sorting);
- virtual void addExpression(const QString &field, const QVariant &value, char relation = '=');
+ virtual void addCondition(const QString &field, const QVariant &value, const QString& relation = QLatin1String("="));
virtual QString sourceName() const;
virtual int fieldNumber(const QString &field) const;
- virtual QVariant value(unsigned int) const;
+ virtual QVariant value(int) const;
virtual QVariant value(const QString &field) const;
virtual bool open();
virtual bool close();
virtual bool moveNext();
virtual bool movePrevious();
virtual bool moveFirst();
virtual bool moveLast();
virtual qint64 at() const;
virtual qint64 recordCount() const;
//Utility Functions
virtual QStringList scriptList() const;
virtual QString scriptCode(const QString& script) const;
- virtual QStringList dataSources() const;
- virtual KReportData* create(const QString& source) const Q_REQUIRED_RESULT;
+ virtual QStringList dataSourceNames() const;
+ virtual KReportDataSource* create(const QString& source) const Q_REQUIRED_RESULT;
private:
class Private;
Private * const d;
bool getSchema(const QString& pluginId = QString());
};
#endif
diff --git a/src/plugins/reports/kexireportdesignview.cpp b/src/plugins/reports/kexireportdesignview.cpp
index 03010b4e0..2c75afd5e 100644
--- a/src/plugins/reports/kexireportdesignview.cpp
+++ b/src/plugins/reports/kexireportdesignview.cpp
@@ -1,214 +1,214 @@
/*
* Kexi Report Plugin
* Copyright (C) 2007-2009 by Adam Pigg
* Copyright (C) 2011 Jarosław Staniek
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "kexireportdesignview.h"
#include
#include
#include "kexisourceselector.h"
#include
#include
#include
#include
#include
#include
#include
KexiReportDesignView::KexiReportDesignView(QWidget *parent, KexiSourceSelector *s)
: KexiView(parent)
{
m_scrollArea = new QScrollArea(this);
layout()->addWidget(m_scrollArea);
m_sourceSelector = s;
m_reportDesigner = 0;
m_editCutAction = KStandardAction::cut(this);
m_editCutAction->setProperty("iconOnly", true);
m_editCopyAction = KStandardAction::copy(this);
m_editCopyAction->setProperty("iconOnly", true);
m_editPasteAction = KStandardAction::paste(this);
m_editPasteAction->setProperty("iconOnly", true);
const KGuiItem del = KStandardGuiItem::del();
m_editDeleteAction = new QAction(del.icon(), del.text(), this);
m_editDeleteAction->setObjectName("editdelete");
m_editDeleteAction->setToolTip(del.toolTip());
m_editDeleteAction->setWhatsThis(del.whatsThis());
m_editDeleteAction->setProperty("iconOnly", true);
m_editSectionAction = new QAction(xi18n("Edit Sections"), this);
m_editSectionAction->setObjectName("sectionedit");
m_itemRaiseAction = new QAction(koIcon("object-order-front"), xi18n("Raise"), this);
m_itemRaiseAction->setObjectName("itemraise");
m_itemLowerAction = new QAction(koIcon("object-order-back"), xi18n("Lower"), this);
m_itemLowerAction->setObjectName("itemlower");
QList al;
QAction *sep = new QAction(QString(), this);
sep->setSeparator(true);
al << m_editCutAction << m_editCopyAction << m_editPasteAction << m_editDeleteAction << sep << m_editSectionAction << sep << m_itemLowerAction << m_itemRaiseAction;
setViewActions(al);
}
KexiReportDesignView::~KexiReportDesignView()
{
}
KPropertySet *KexiReportDesignView::propertySet()
{
return m_reportDesigner->itemPropertySet();
}
void KexiReportDesignView::slotDesignerPropertySetChanged()
{
propertySetReloaded(true);
propertySetSwitched();
}
KDbObject* KexiReportDesignView::storeNewData(const KDbObject& object,
KexiView::StoreNewDataOptions options,
bool *cancel)
{
KDbObject *s = KexiView::storeNewData(object, options, cancel);
if (!s || *cancel) {
delete s;
return 0;
}
qDebug() << "new id:" << s->id();
if (!storeData()) {
//failure: remove object's object data to avoid garbage
KDbConnection *conn = KexiMainWindowIface::global()->project()->dbConnection();
conn->removeObject(s->id());
delete s;
return 0;
}
return s;
}
tristate KexiReportDesignView::storeData(bool dontAsk)
{
Q_UNUSED(dontAsk);
QDomDocument doc("kexireport");
QDomElement root = doc.createElement("kexireport");
QDomElement conndata = m_sourceSelector->connectionData();
if (conndata.isNull())
qDebug() << "Null conn data!";
root.appendChild(m_reportDesigner->document());
root.appendChild(conndata);
doc.appendChild(root);
QString src = doc.toString();
qDebug() << src;
if (storeDataBlock(src, "layout")) {
qDebug() << "Saved OK";
setDirty(false);
return true;
}
qDebug() << "NOT Saved OK";
return false;
}
tristate KexiReportDesignView::beforeSwitchTo(Kexi::ViewMode mode, bool *dontStore)
{
qDebug() << mode;
*dontStore = true;
if (m_reportDesigner && mode == Kexi::DataViewMode) {
qDebug() << "Saving temp data";
tempData()->reportDefinition = m_reportDesigner->document();
qDebug() << m_reportDesigner->document().toDocument().toString();
tempData()->reportSchemaChangedInPreviousView = true;
}
return true;
}
tristate KexiReportDesignView::afterSwitchFrom(Kexi::ViewMode mode)
{
Q_UNUSED(mode);
if (tempData()->reportDefinition.isNull()) {
m_reportDesigner = new KReportDesigner(this);
} else {
if (m_reportDesigner) {
m_scrollArea->takeWidget();
delete m_reportDesigner;
m_reportDesigner = 0;
}
m_reportDesigner = new KReportDesigner(this, tempData()->reportDefinition);
m_sourceSelector->setConnectionData(tempData()->connectionDefinition);
}
connect(m_reportDesigner, SIGNAL(itemInserted(QString)), this, SIGNAL(itemInserted(QString)));
m_scrollArea->setWidget(m_reportDesigner);
connect(m_reportDesigner, SIGNAL(propertySetChanged()), this, SLOT(slotDesignerPropertySetChanged()));
connect(m_reportDesigner, SIGNAL(dirty()), this, SLOT(setDirty()));
//Added default keyboard shortcuts for the actions
QShortcut *cutShortcut = new QShortcut(QKeySequence(QKeySequence::Cut), m_reportDesigner);
QShortcut *copyShortcut = new QShortcut(QKeySequence(QKeySequence::Copy), m_reportDesigner);
QShortcut *pasteShortcut = new QShortcut(QKeySequence(QKeySequence::Paste), m_reportDesigner);
QShortcut *deleteShortcut = new QShortcut(QKeySequence(QKeySequence::Delete), m_reportDesigner);
connect(cutShortcut, SIGNAL(activated()), m_reportDesigner, SLOT(slotEditCut()));
connect(copyShortcut, SIGNAL(activated()), m_reportDesigner, SLOT(slotEditCopy()));
connect(pasteShortcut, SIGNAL(activated()), m_reportDesigner, SLOT(slotEditPaste()));
connect(deleteShortcut, SIGNAL(activated()), m_reportDesigner, SLOT(slotEditDelete()));
//Edit Actions
connect(m_editCutAction, SIGNAL(triggered()), m_reportDesigner, SLOT(slotEditCut()));
connect(m_editCopyAction, SIGNAL(triggered()), m_reportDesigner, SLOT(slotEditCopy()));
connect(m_editPasteAction, SIGNAL(triggered()), m_reportDesigner, SLOT(slotEditPaste()));
connect(m_editDeleteAction, SIGNAL(triggered()), m_reportDesigner, SLOT(slotEditDelete()));
connect(m_editSectionAction, SIGNAL(triggered()), m_reportDesigner, SLOT(slotSectionEditor()));
//Raise/Lower
connect(m_itemRaiseAction, SIGNAL(triggered()), m_reportDesigner, SLOT(slotRaiseSelected()));
connect(m_itemLowerAction, SIGNAL(triggered()), m_reportDesigner, SLOT(slotLowerSelected()));
return true;
}
KexiReportPartTempData* KexiReportDesignView::tempData() const
{
return static_cast(window()->data());
}
void KexiReportDesignView::slotSourceDataChanged()
{
- m_reportDesigner->setReportData(m_sourceSelector->createSourceData());
+ m_reportDesigner->setDataSource(m_sourceSelector->createSourceData());
tempData()->connectionDefinition = m_sourceSelector->connectionData();
setDirty(true);
}
void KexiReportDesignView::triggerAction(const QString &action)
{
m_reportDesigner->slotItem(action);
}
diff --git a/src/plugins/reports/kexireportdesignview.h b/src/plugins/reports/kexireportdesignview.h
index 98f283786..0a605fb1e 100644
--- a/src/plugins/reports/kexireportdesignview.h
+++ b/src/plugins/reports/kexireportdesignview.h
@@ -1,82 +1,82 @@
/*
* Kexi Report Plugin
* Copyright (C) 2007-2009 by Adam Pigg
* Copyright (C) 2011 Jarosław Staniek
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KEXIREPORTDESIGNVIEW_H
#define KEXIREPORTDESIGNVIEW_H
#include
#include
#include
#include
-#include
+#include
class QScrollArea;
class KexiSourceSelector;
/**
@author
*/
class KexiReportDesignView : public KexiView
{
Q_OBJECT
public:
KexiReportDesignView(QWidget *parent, KexiSourceSelector*);
~KexiReportDesignView();
virtual tristate afterSwitchFrom(Kexi::ViewMode mode);
virtual tristate beforeSwitchTo(Kexi::ViewMode mode, bool *dontStore);
void triggerAction(const QString &);
Q_SIGNALS:
void itemInserted(const QString& entity);
private:
KReportDesigner *m_reportDesigner;
KexiReportPartTempData* tempData() const;
QScrollArea * m_scrollArea;
//Actions
QAction *m_editCutAction;
QAction *m_editCopyAction;
QAction *m_editPasteAction;
QAction *m_editDeleteAction;
QAction *m_editSectionAction;
QAction *m_itemRaiseAction;
QAction *m_itemLowerAction;
KexiSourceSelector *m_sourceSelector;
protected:
virtual KPropertySet *propertySet();
virtual tristate storeData(bool dontAsk = false);
virtual KDbObject* storeNewData(const KDbObject& object,
KexiView::StoreNewDataOptions options,
bool *cancel);
private Q_SLOTS:
void slotDesignerPropertySetChanged();
public Q_SLOTS:
void slotSourceDataChanged();
};
#endif
diff --git a/src/plugins/reports/kexireportpart.h b/src/plugins/reports/kexireportpart.h
index 22699292e..55630abbb 100644
--- a/src/plugins/reports/kexireportpart.h
+++ b/src/plugins/reports/kexireportpart.h
@@ -1,88 +1,88 @@
/*
* Kexi Report Plugin
* Copyright (C) 2007-2008 by Adam Pigg
* Copyright (C) 2011-2015 Jarosław Staniek
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef _KEXIREPORTPART_H_
#define _KEXIREPORTPART_H_
#include
#include
-#include
+#include
#include
class KexiReportPartTempData : public KexiWindowData
{
Q_OBJECT
public:
explicit KexiReportPartTempData(QObject* parent);
QDomElement reportDefinition;
QDomElement connectionDefinition;
/*! true, if \a document member has changed in previous view. Used on view switching.
Check this flag to see if we should refresh data for DataViewMode. */
bool reportSchemaChangedInPreviousView;
};
/**
* @short Application Main Window
* @author Adam Pigg
* @version 0.1
*/
class KexiReportPart : public KexiPart::Part
{
Q_OBJECT
public:
/**
* Default Constructor
*/
KexiReportPart(QObject *parent, const QVariantList &l);
/**
* Default Destructor
*/
virtual ~KexiReportPart();
virtual void setupCustomPropertyPanelTabs(QTabWidget *tab);
virtual KLocalizedString i18nMessage(const QString& englishMessage,
KexiWindow* window) const;
protected:
virtual KexiView* createView(QWidget *parent, KexiWindow* win,
KexiPart::Item *item, Kexi::ViewMode = Kexi::DataViewMode,
QMap* staticObjectArgs = 0);
virtual KexiWindowData* createWindowData(KexiWindow* window);
virtual void initPartActions();
virtual KDbObject* loadSchemaObject(KexiWindow *window,
const KDbObject& object, Kexi::ViewMode viewMode, bool *ownedByWindow);
private Q_SLOTS:
void slotToolboxActionTriggered(bool checked);
//! Unchecks toolbox action for @a entity after it is used.
void slotItemInserted(const QString& entity);
private:
class Private;
Private* d;
};
#endif // _KEXIREPORTPART_H_
diff --git a/src/plugins/reports/kexireportview.cpp b/src/plugins/reports/kexireportview.cpp
index 965452a29..34575e88b 100644
--- a/src/plugins/reports/kexireportview.cpp
+++ b/src/plugins/reports/kexireportview.cpp
@@ -1,473 +1,473 @@
/*
* Kexi Report Plugin
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
Copyright (C) 2014 Jarosław Staniek
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "kexireportview.h"
#include
#include "kexidbreportdata.h"
#ifndef KEXI_MOBILE
#include
//! @todo KEXI3
#if 0
#include "keximigratereportdata.h"
#endif
#endif
#include
#include
#include
//! @todo KEXI3 #include "../scripting/kexiscripting/kexiscriptadaptor.h"
#include
#include
#include
#include
#include "krscriptfunctions.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
KexiReportView::KexiReportView(QWidget *parent)
: KexiView(parent), m_preRenderer(0), m_functions(0) //! @todo KEXI3, m_kexi(0)
{
setObjectName("KexiReportDesigner_DataView");
m_reportView = new KReportView(this);
layout()->addWidget(m_reportView);
#ifndef KEXI_MOBILE
m_pageSelector = new KexiRecordNavigator(*m_reportView->scrollArea(), m_reportView);
m_pageSelector->setInsertingButtonVisible(false);
m_pageSelector->setInsertingEnabled(false);
m_pageSelector->setLabelText(xi18nc("Page selector label", "Page:"));
m_pageSelector->setButtonToolTipText(KexiRecordNavigator::ButtonFirst, xi18n("Go to first page"));
m_pageSelector->setButtonWhatsThisText(KexiRecordNavigator::ButtonFirst, xi18n("Goes to first page"));
m_pageSelector->setButtonToolTipText(KexiRecordNavigator::ButtonPrevious, xi18n("Go to previous page"));
m_pageSelector->setButtonWhatsThisText(KexiRecordNavigator::ButtonPrevious, xi18n("Goes to previous page"));
m_pageSelector->setButtonToolTipText(KexiRecordNavigator::ButtonNext, xi18n("Go to next page"));
m_pageSelector->setButtonWhatsThisText(KexiRecordNavigator::ButtonNext, xi18n("Goes to next page"));
m_pageSelector->setButtonToolTipText(KexiRecordNavigator::ButtonLast, xi18n("Go to last page"));
m_pageSelector->setButtonWhatsThisText(KexiRecordNavigator::ButtonLast, xi18n("Goes to last page"));
m_pageSelector->setNumberFieldToolTips(xi18n("Current page number"), xi18n("Number of pages"));
m_pageSelector->setRecordHandler(this);
#endif
// -- setup local actions
QList viewActions;
QAction* a;
#ifndef KEXI_MOBILE
viewActions << (a = new QAction(koIcon("document-print"), xi18n("Print"), this));
a->setObjectName("print_report");
a->setToolTip(xi18n("Print report"));
a->setWhatsThis(xi18n("Prints the current report."));
connect(a, SIGNAL(triggered()), this, SLOT(slotPrintReport()));
KActionMenu *exportMenu = new KActionMenu(koIcon("document-export"), xi18nc("@title:menu","E&xport As"), this);
exportMenu->setObjectName("report_export_as");
exportMenu->setDelayed(false);
#endif
#ifdef KEXI_MOBILE
viewActions << (a = new QAction(xi18n("Export:"), this));
a->setEnabled(false); //!TODO this is a bit of a dirty way to add what looks like a label to the toolbar!
// " ", not "", is said to be needed in maemo, the icon didn't display properly without it
viewActions << (a = new QAction(koIcon("application-vnd.oasis.opendocument.text"), QLatin1String(" "), this));
#else
exportMenu->addAction(a = new QAction(koIcon("application-vnd.oasis.opendocument.text"),
xi18nc("open dialog to export as text document", "Text Document..."), this));
#endif
a->setObjectName("export_as_text_document");
a->setToolTip(xi18n("Export the report as a text document (in OpenDocument Text format)"));
a->setWhatsThis(xi18n("Exports the report as a text document (in OpenDocument Text format)."));
a->setEnabled(true);
connect(a, SIGNAL(triggered()), this, SLOT(slotExportAsTextDocument()));
#ifdef KEXI_MOBILE
viewActions << (a = new QAction(koIcon("application-pdf"), QLatin1String(" "), this));
#else
exportMenu->addAction(a = new QAction(koIcon("application-pdf"),
xi18nc("Portable Document Format...", "PDF..."), this));
#endif
a->setObjectName("export_as_pdf");
a->setToolTip(xi18n("Export as PDF"));
a->setWhatsThis(xi18n("Exports the current report as PDF."));
a->setEnabled(true);
connect(a, SIGNAL(triggered()), this, SLOT(slotExportAsPdf()));
#ifdef KEXI_MOBILE
viewActions << (a = new QAction(koIcon("application-vnd.oasis.opendocument.spreadsheet"), QLatin1String(" "), this));
#else
exportMenu->addAction(a = new QAction(koIcon("application-vnd.oasis.opendocument.spreadsheet"),
xi18nc("open dialog to export as spreadsheet", "Spreadsheet..."), this));
#endif
a->setObjectName("export_as_spreadsheet");
a->setToolTip(xi18n("Export the report as a spreadsheet (in OpenDocument Spreadsheet format)"));
a->setWhatsThis(xi18n("Exports the report as a spreadsheet (in OpenDocument Spreadsheet format)."));
a->setEnabled(true);
connect(a, SIGNAL(triggered()), this, SLOT(slotExportAsSpreadsheet()));
#ifdef KEXI_MOBILE
viewActions << (a = new QAction(koIcon("text-html"), QLatin1String(" "), this));
#else
exportMenu->addAction(a = new QAction(koIcon("text-html"),
xi18nc("open dialog to export as web page", "Web Page..."), this));
#endif
a->setObjectName("export_as_web_page");
a->setToolTip(xi18n("Export the report as a web page (in HTML format)"));
a->setWhatsThis(xi18n("Exports the report as a web page (in HTML format)."));
a->setEnabled(true);
connect(a, SIGNAL(triggered()), this, SLOT(slotExportAsWebPage()));
setViewActions(viewActions);
#ifndef KEXI_MOBILE
// setup main menu actions
QList mainMenuActions;
mainMenuActions << exportMenu;
setMainMenuActions(mainMenuActions);
#endif
}
KexiReportView::~KexiReportView()
{
qDebug();
delete m_preRenderer;
}
void KexiReportView::slotPrintReport()
{
QScopedPointer renderer(m_factory.createInstance("print"));
if (!renderer) {
return;
}
QPrinter printer(QPrinter::HighResolution);
QPrintDialog dialog(&printer, this);
if (dialog.exec() == QDialog::Accepted) {
KReportRendererContext cxt;
QPainter painter;
cxt.setPrinter(&printer);
cxt.setPainter(&painter);
renderer->render(cxt, m_preRenderer->document());
}
}
void KexiReportView::slotExportAsPdf()
{
QScopedPointer renderer(m_factory.createInstance("print"));
if (renderer) {
KReportRendererContext cxt;
cxt.setUrl(getExportUrl(QLatin1String("application/pdf"),
xi18n("Export Report as PDF"),
"kfiledialog:///LastVisitedPDFExportPath/",
"pdf"));
if (!cxt.url().isValid()) {
return;
}
QPrinter printer;
QPainter painter;
printer.setOutputFileName(cxt.url().path());
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setColorMode(QPrinter::Color);
painter.begin(&printer);
cxt.setPrinter(&printer);
cxt.setPainter(&painter);
if (!renderer->render(cxt, m_preRenderer->document())) {
KMessageBox::error(this,
xi18n("Exporting the report as PDF to %1 failed.", cxt.url().toDisplayString()),
xi18n("Export Failed"));
} else {
openExportedDocument(cxt.url());
}
}
}
QUrl KexiReportView::getExportUrl(const QString &mimetype, const QString &caption,
const QString &lastExportPath, const QString &extension)
{
QString defaultSavePath;
QString recentDirClass;
defaultSavePath = KFileWidget::getStartUrl(QUrl(lastExportPath), recentDirClass).toLocalFile()
+ '/' + window()->partItem()->captionOrName() + '.' + extension;
// loop until an url has been chosen or the file selection has been cancelled
const QMimeDatabase db;
const QString filterString = db.mimeTypeForName(mimetype).filterString();
return QFileDialog::getSaveFileUrl(this, caption, QUrl(defaultSavePath), filterString);
}
void KexiReportView::openExportedDocument(const QUrl &destination)
{
const int answer =
KMessageBox::questionYesNo(
this,
xi18n("Do you want to open exported document?"),
QString(),
KStandardGuiItem::open(),
KStandardGuiItem::close());
if (answer == KMessageBox::Yes) {
(void)new KRun(destination, this->topLevelWidget());
}
}
void KexiReportView::slotExportAsSpreadsheet()
{
QScopedPointer renderer(m_factory.createInstance("ods"));
if (renderer) {
KReportRendererContext cxt;
cxt.setUrl(getExportUrl(QLatin1String("application/vnd.oasis.opendocument.spreadsheet"),
xi18n("Export Report as Spreadsheet"),
"kfiledialog:///LastVisitedODSExportPath/",
"ods"));
if (!cxt.url().isValid()) {
return;
}
if (!renderer->render(cxt, m_preRenderer->document())) {
KMessageBox::error(this,
xi18n("Failed to export the report as spreadsheet to %1.", cxt.url().toDisplayString()),
xi18n("Export Failed"));
} else {
openExportedDocument(cxt.url());
}
}
}
void KexiReportView::slotExportAsTextDocument()
{
QScopedPointer renderer(m_factory.createInstance("odt"));
//! @todo Show error or don't show the commands to the user if the plugin isn't available.
//! The same for other createInstance() calls.
if (renderer) {
KReportRendererContext cxt;
cxt.setUrl(getExportUrl(QLatin1String("application/vnd.oasis.opendocument.text"),
xi18n("Export Report as Text Document"),
"kfiledialog:///LastVisitedODTExportPath/",
"odt"));
if (!cxt.url().isValid()) {
return;
}
if (!renderer->render(cxt, m_preRenderer->document())) {
KMessageBox::error(this,
xi18n("Exporting the report as text document to %1 failed.", cxt.url().toDisplayString()),
xi18n("Export Failed"));
} else {
openExportedDocument(cxt.url());
}
}
}
void KexiReportView::slotExportAsWebPage()
{
const QString dialogTitle = xi18n("Export Report as Web Page");
KReportRendererContext cxt;
cxt.setUrl(getExportUrl(QLatin1String("text/html"),
dialogTitle,
"kfiledialog:///LastVisitedHTMLExportPath/",
"html"));
if (!cxt.url().isValid()) {
return;
}
const int answer =
KMessageBox::questionYesNo(
this,
xi18nc("@info",
"Would you like to use Cascading Style Sheets (CSS) in the exported "
"web page or use HTML tables?"
"CSS give output closer to the original."),
dialogTitle,
KGuiItem(xi18nc("@action:button", "Use CSS")),
KGuiItem(xi18nc("@action:button", "Use Table")));
QScopedPointer renderer(
m_factory.createInstance(answer == KMessageBox::Yes ? "htmlcss" : "htmltable"));
if (!renderer) {
return;
}
if (!renderer->render(cxt, m_preRenderer->document())) {
KMessageBox::error(this,
xi18n("Exporting the report as web page to %1 failed.", cxt.url().toDisplayString()),
xi18n("Export Failed"));
} else {
openExportedDocument(cxt.url());
}
}
tristate KexiReportView::beforeSwitchTo(Kexi::ViewMode mode, bool *dontStore)
{
Q_UNUSED(mode);
Q_UNUSED(dontStore);
return true;
}
tristate KexiReportView::afterSwitchFrom(Kexi::ViewMode mode)
{
Q_UNUSED(mode);
if (tempData()->reportSchemaChangedInPreviousView) {
tempData()->reportSchemaChangedInPreviousView = false;
qDebug() << "Schema changed";
delete m_preRenderer;
//qDebug() << tempData()->reportDefinition.tagName();
m_preRenderer = new KReportPreRenderer(tempData()->reportDefinition);
if (m_preRenderer->isValid()) {
- KReportData *reportData = 0;
+ KReportDataSource *reportData = 0;
if (!tempData()->connectionDefinition.isNull()) {
reportData = createSourceData(tempData()->connectionDefinition);
}
m_preRenderer->setSourceData(reportData);
m_preRenderer->setName(window()->partItem()->name());
//Add a kexi object to provide kexidb and extra functionality
//! @todo KEXI3 if we want this if(!m_kexi) {
// m_kexi = new KexiScriptAdaptor();
// }
// m_preRenderer->registerScriptObject(m_kexi, "Kexi");
//If using a kexidb source, add a functions scripting object
if (tempData()->connectionDefinition.attribute("type") == "internal") {
m_functions = new KRScriptFunctions(reportData, KexiMainWindowIface::global()->project()->dbConnection());
m_preRenderer->registerScriptObject(m_functions, "field");
connect(m_preRenderer, SIGNAL(groupChanged(QMap)),
m_functions, SLOT(setGroupData(QMap)));
}
connect(m_preRenderer, SIGNAL(finishedAllASyncItems()), this, SLOT(finishedAllASyncItems()));
if (!m_preRenderer->generateDocument()) {
qWarning() << "Could not generate report document";
return false;
}
m_reportView->setDocument(m_preRenderer->document());
#ifndef KEXI_MOBILE
m_pageSelector->setRecordCount(m_reportView->pageCount());
m_pageSelector->setCurrentRecordNumber(1);
#endif
} else {
KMessageBox::error(this, xi18n("Report schema appears to be invalid or corrupt"), xi18n("Opening failed"));
}
}
return true;
}
-KReportData* KexiReportView::createSourceData(QDomElement e)
+KReportDataSource* KexiReportView::createSourceData(QDomElement e)
{
- KReportData *kodata = 0;
+ KReportDataSource *kodata = 0;
if (e.attribute("type") == "internal" && !e.attribute("source").isEmpty()) {
kodata = new KexiDBReportData(e.attribute("source"), KexiMainWindowIface::global()->project()->dbConnection());
}
#ifndef KEXI_MOBILE
//! @todo KEXI3
#if 0
if (e.attribute("type") == "external") {
kodata = new KexiMigrateReportData(e.attribute("source"));
}
#endif
#endif
return kodata;
}
KexiReportPartTempData* KexiReportView::tempData() const
{
return static_cast(window()->data());
}
void KexiReportView::addNewRecordRequested()
{
}
void KexiReportView::moveToFirstRecordRequested()
{
m_reportView->moveToFirstPage();
#ifndef KEXI_MOBILE
m_pageSelector->setCurrentRecordNumber(m_reportView->currentPage());
#endif
}
void KexiReportView::moveToLastRecordRequested()
{
m_reportView->moveToLastPage();
#ifndef KEXI_MOBILE
m_pageSelector->setCurrentRecordNumber(m_reportView->currentPage());
#endif
}
void KexiReportView::moveToNextRecordRequested()
{
m_reportView->moveToNextPage();
#ifndef KEXI_MOBILE
m_pageSelector->setCurrentRecordNumber(m_reportView->currentPage());
#endif
}
void KexiReportView::moveToPreviousRecordRequested()
{
m_reportView->moveToPreviousPage();
#ifndef KEXI_MOBILE
m_pageSelector->setCurrentRecordNumber(m_reportView->currentPage());
#endif
}
void KexiReportView::moveToRecordRequested(int r)
{
Q_UNUSED(r);
}
int KexiReportView::currentRecord() const
{
return m_reportView->currentPage();
}
int KexiReportView::recordCount() const
{
return m_reportView->pageCount();
}
void KexiReportView::finishedAllASyncItems()
{
m_reportView->refreshCurrentPage();
}
diff --git a/src/plugins/reports/kexireportview.h b/src/plugins/reports/kexireportview.h
index 3b9bc39c5..8f9155dbc 100644
--- a/src/plugins/reports/kexireportview.h
+++ b/src/plugins/reports/kexireportview.h
@@ -1,90 +1,90 @@
/*
* Kexi Report Plugin
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KEXIREPORTVIEW_H
#define KEXIREPORTVIEW_H
#include
#include
#include
#include
#include
#include "kexireportpart.h"
class KReportPreRenderer;
class ORODocument;
class KReportView;
//! @todo KEXI3 class KexiScriptAdaptor;
class KRScriptFunctions;
#ifndef KEXI_MOBILE
class KexiRecordNavigator;
#endif
/**
@author Adam Pigg
*/
class KexiReportView : public KexiView, public KexiRecordNavigatorHandler
{
Q_OBJECT
public:
explicit KexiReportView(QWidget *parent);
~KexiReportView();
virtual tristate afterSwitchFrom(Kexi::ViewMode mode);
virtual tristate beforeSwitchTo(Kexi::ViewMode mode, bool *dontStore);
virtual void addNewRecordRequested();
virtual void moveToFirstRecordRequested();
virtual void moveToLastRecordRequested();
virtual void moveToNextRecordRequested();
virtual void moveToPreviousRecordRequested();
virtual void moveToRecordRequested(int r);
virtual int currentRecord() const;
virtual int recordCount() const;
private:
KReportPreRenderer *m_preRenderer;
KReportView *m_reportView;
#ifndef KEXI_MOBILE
KexiRecordNavigator *m_pageSelector;
#endif
KexiReportPartTempData* tempData() const;
- KReportData* createSourceData(QDomElement e);
+ KReportDataSource* createSourceData(QDomElement e);
//! @todo KEXI3 KexiScriptAdaptor *m_kexi;
KRScriptFunctions *m_functions;
KReportRendererFactory m_factory;
QUrl getExportUrl(const QString &mimetype, const QString &caption,
const QString &lastExportPathOrVariable, const QString &extension);
private Q_SLOTS:
void slotPrintReport();
void slotExportAsPdf();
void slotExportAsSpreadsheet();
void slotExportAsWebPage();
void slotExportAsTextDocument();
void openExportedDocument(const QUrl &destination);
void finishedAllASyncItems();
};
#endif
diff --git a/src/plugins/reports/kexisourceselector.cpp b/src/plugins/reports/kexisourceselector.cpp
index c29756680..0cc217a76 100644
--- a/src/plugins/reports/kexisourceselector.cpp
+++ b/src/plugins/reports/kexisourceselector.cpp
@@ -1,170 +1,170 @@
/*
* Kexi Report Plugin
* Copyright (C) 2007-2009 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "kexisourceselector.h"
#include "KexiDataSourceComboBox.h"
#include
#include
#include
#include
#include
#include
#include
#include
//#define NO_EXTERNAL_SOURCES
#ifdef NO_EXTERNAL_SOURCES
//! @todo KEXI3 enable external data sources for 2.3
#endif
class Q_DECL_HIDDEN KexiSourceSelector::Private
{
public:
Private()
{
}
~Private()
{
}
KDbConnection *conn;
QVBoxLayout *layout;
QComboBox *sourceType;
KexiDataSourceComboBox *internalSource;
QLineEdit *externalSource;
QPushButton *setData;
};
KexiSourceSelector::KexiSourceSelector(KexiProject* project, QWidget* parent)
: QWidget(parent)
, d(new Private)
{
d->conn = project->dbConnection();
d->layout = new QVBoxLayout(this);
d->sourceType = new QComboBox(this);
d->internalSource = new KexiDataSourceComboBox(this);
d->internalSource->setProject(project);
d->externalSource = new QLineEdit(this);
d->setData = new QPushButton(xi18n("Set Data"));
connect(d->setData, &QPushButton::clicked, this, &KexiSourceSelector::sourceDataChanged);
d->sourceType->addItem(xi18n("Internal"), QVariant("internal"));
d->sourceType->addItem(xi18n("External"), QVariant("external"));
#ifndef NO_EXTERNAL_SOURCES
//!@TODO enable when adding external data
d->layout->addWidget(new QLabel(xi18n("Source type:"), this));
d->layout->addWidget(d->sourceType);
d->layout->addSpacing(10);
#else
d->sourceType->setVisible(false);
d->externalSource->setVisible(false);
#endif
d->layout->addWidget(new QLabel(xi18n("Report's data source:"), this));
d->layout->addWidget(d->internalSource);
d->layout->addSpacing(10);
#ifndef NO_EXTERNAL_SOURCES
d->layout->addWidget(new QLabel(xi18n("External source:"), this));
d->layout->addWidget(d->externalSource);
#endif
d->layout->addSpacing(20);
d->layout->addWidget(d->setData);
d->layout->addStretch();
setLayout(d->layout);
}
KexiSourceSelector::~KexiSourceSelector()
{
delete d;
}
void KexiSourceSelector::setConnectionData(const QDomElement &c)
{
if (c.attribute("type") == "internal") {
d->sourceType->setCurrentIndex(d->sourceType->findData("internal"));
d->internalSource->setCurrentIndex(d->internalSource->findText(c.attribute("source")));
}
if (c.attribute("type") == "external") {
d->sourceType->setCurrentIndex(d->sourceType->findText("external"));
d->externalSource->setText(c.attribute("source"));
}
emit sourceDataChanged();
}
QDomElement KexiSourceSelector::connectionData()
{
qDebug();
QDomDocument dd;
QDomElement conndata = dd.createElement("connection");
#ifndef NO_EXTERNAL_SOURCES
//!@TODO Make a better gui for selecting external data source
conndata.setAttribute("type", d->sourceType->itemData(d->sourceType->currentIndex()).toString());
if (d->sourceType->itemData(d->sourceType->currentIndex()).toString() == "internal") {
conndata.setAttribute("source", d->internalSource->currentText());
} else {
conndata.setAttribute("source", d->externalSource->text());
}
#else
conndata.setAttribute("type", "internal");
conndata.setAttribute("source", d->internalSource->currentText());
#endif
return conndata;
}
-KReportData* KexiSourceSelector::createSourceData() const
+KReportDataSource* KexiSourceSelector::createSourceData() const
{
//!@TODO Fix when enable external data
#ifndef NO_EXTERNAL_SOURCES
if (d->sourceType->itemData(d->sourceType->currentIndex()).toString() == "internal" && d->internalSource->isSelectionValid()) {
return new KexiDBReportData(d->internalSource->selectedName(), d->internalSource->selectedPluginId(), d->conn);
}
#ifndef KEXI_MOBILE
//! @todo KEXI3
#if 0
if (d->sourceType->itemData(d->sourceType->currentIndex()).toString() == "external") {
return new KexiMigrateReportData(d->externalSource->text());
return d->kexiMigrateData;
}
#endif
#endif
#else
if (d->internalSource->isSelectionValid()) {
return new KexiDBReportData(d->internalSource->selectedName(), d->conn);
}
#endif
return 0;
}
diff --git a/src/plugins/reports/kexisourceselector.h b/src/plugins/reports/kexisourceselector.h
index 799c4c7f0..542e4933a 100644
--- a/src/plugins/reports/kexisourceselector.h
+++ b/src/plugins/reports/kexisourceselector.h
@@ -1,55 +1,55 @@
/*
* Kexi Report Plugin
* Copyright (C) 2007-2016 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KEXISOURCESELECTOR_H
#define KEXISOURCESELECTOR_H
#include
-#include
+#include
#include "kexidbreportdata.h"
#ifdef HAVE_KEXI_MIGRATE
#include "keximigratereportdata.h"
#endif
class QDomElement;
class KexiProject;
//! @todo rename to KexiReportDataSourcePage
//! @todo use KexiPropertyPaneViewBase
class KexiSourceSelector : public QWidget
{
Q_OBJECT
public:
explicit KexiSourceSelector(KexiProject* project, QWidget* parent = 0);
~KexiSourceSelector();
- KReportData* createSourceData() const Q_REQUIRED_RESULT;
+ KReportDataSource* createSourceData() const Q_REQUIRED_RESULT;
void setConnectionData(const QDomElement &c);
QDomElement connectionData();
Q_SIGNALS:
void sourceDataChanged();
private:
class Private;
Private * const d;
};
#endif // KEXISOURCESELECTOR_H
diff --git a/src/plugins/reports/krscriptfunctions.cpp b/src/plugins/reports/krscriptfunctions.cpp
index f7434bc7d..6eb2f3df4 100644
--- a/src/plugins/reports/krscriptfunctions.cpp
+++ b/src/plugins/reports/krscriptfunctions.cpp
@@ -1,122 +1,122 @@
/*
* Kexi Report Plugin
* Copyright (C) 2007-2008 by Adam Pigg
* Copyright (C) 2012 Jarosław Staniek
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "krscriptfunctions.h"
#include
#include
#include
-KRScriptFunctions::KRScriptFunctions(const KReportData* kodata, KDbConnection* conn)
+KRScriptFunctions::KRScriptFunctions(const KReportDataSource* kodata, KDbConnection* conn)
{
m_cursor = kodata;
m_connection = conn;
if (kodata) {
m_source = kodata->sourceName();
}
}
KRScriptFunctions::~KRScriptFunctions()
{
}
void KRScriptFunctions::setGroupData(const QMap& groupData)
{
m_groupData = groupData;
}
qreal KRScriptFunctions::math(const QString &function, const QString &field)
{
QString ret = QLatin1String("0.0");
if (!m_connection) {
return 0.0;
}
KDbEscapedString sql = KDbEscapedString("SELECT " + function + "(" + field + ") FROM (" + m_source + ")");
if (!m_groupData.isEmpty()) {
sql += " WHERE(" + where() + ')';
}
qDebug() << sql;
m_connection->querySingleString(sql,&ret);
return ret.toDouble();
}
qreal KRScriptFunctions::sum(const QString &field)
{
return math("SUM", field);
}
qreal KRScriptFunctions::avg(const QString &field)
{
return math("AVG", field);
}
qreal KRScriptFunctions::min(const QString &field)
{
return math("MIN", field);
}
qreal KRScriptFunctions::max(const QString &field)
{
return math("MAX", field);
}
qreal KRScriptFunctions::count(const QString &field)
{
return math("COUNT", field);
}
QVariant KRScriptFunctions::value(const QString &field)
{
QVariant val;
if (!m_cursor) {
qDebug() << "No cursor to get value of field " << field;
return val;
}
QStringList fields = m_cursor->fieldNames();
val = m_cursor->value(fields.indexOf(field));
if (val.type() == QVariant::String) {
// UTF-8 values are expected so convert this
return val.toString().toUtf8();
}
return val;
}
KDbEscapedString KRScriptFunctions::where()
{
QByteArray w;
QMap::const_iterator i = m_groupData.constBegin();
while (i != m_groupData.constEnd()) {
w += '(' + i.key().toUtf8() + QByteArrayLiteral(" = '") + i.value().toString().toUtf8() + QByteArrayLiteral("') AND ");
++i;
}
w.chop(4);
//kreportDebug() << w;
return KDbEscapedString(w);
}
diff --git a/src/plugins/reports/krscriptfunctions.h b/src/plugins/reports/krscriptfunctions.h
index 0ff087592..953dd5007 100644
--- a/src/plugins/reports/krscriptfunctions.h
+++ b/src/plugins/reports/krscriptfunctions.h
@@ -1,62 +1,62 @@
/*
* Kexi Report Plugin
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KRSCRIPTFUNCTIONS_H
#define KRSCRIPTFUNCTIONS_H
-#include
+#include
#include
#include
class KDbConnection;
class KDbCursor;
/**
@author
*/
class KRScriptFunctions : public KReportGroupTracker
{
Q_OBJECT
public:
- KRScriptFunctions(const KReportData *, KDbConnection*);
+ KRScriptFunctions(const KReportDataSource *, KDbConnection*);
~KRScriptFunctions();
private:
KDbConnection *m_connection;
- const KReportData *m_cursor;
+ const KReportDataSource *m_cursor;
QString m_source;
qreal math(const QString &, const QString &);
QMap m_groupData;
KDbEscapedString where();
public Q_SLOTS:
virtual void setGroupData(const QMap &groupData);
qreal sum(const QString &);
qreal avg(const QString &);
qreal min(const QString &);
qreal max(const QString &);
qreal count(const QString &);
QVariant value(const QString &);
};
#endif