diff --git a/kexi/plugins/reports/kexidbreportdata.cpp b/kexi/plugins/reports/kexidbreportdata.cpp index 72c405d102b..376543d65ba 100644 --- a/kexi/plugins/reports/kexidbreportdata.cpp +++ b/kexi/plugins/reports/kexidbreportdata.cpp @@ -1,404 +1,404 @@ /* * Kexi Report Plugin * Copyright (C) 2007-2009 by Adam Pigg (adam@piggz.co.uk) * Copyright (C) 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 . */ #include "kexidbreportdata.h" #include "kexireportview.h" #include #include #include #include class KexiDBReportData::Private { public: explicit Private(KexiDB::Connection *pDb, KexiReportView *v) : cursor(0), connection(pDb), view(v), originalSchema(0), copySchema(0) { } ~Private() { delete copySchema; delete originalSchema; delete cursor; } QString objectName; KexiDB::Cursor *cursor; KexiDB::Connection * const connection; KexiReportView * const view; KexiDB::QuerySchema *originalSchema; KexiDB::QuerySchema *copySchema; }; KexiDBReportData::KexiDBReportData (const QString &objectName, KexiDB::Connection * pDb, KexiReportView *view) : d(new Private(pDb, view)) { d->objectName = objectName; getSchema(); } KexiDBReportData::KexiDBReportData(const QString& objectName, const QString& partClass, KexiDB::Connection* pDb, KexiReportView *view) : d(new Private(pDb, view)) { d->objectName = objectName; getSchema(partClass); } void KexiDBReportData::setSorting(const QList& sorting) { if (d->copySchema) { if (sorting.isEmpty()) return; KexiDB::OrderByColumnList order; for (int i = 0; i < sorting.count(); i++) { order.appendField(*d->copySchema, sorting[i].field, sorting[i].order == Qt::AscendingOrder); } d->copySchema->setOrderByColumnList(order); } else { kDebug() << "Unable to sort null schema"; } } void KexiDBReportData::addExpression(const QString& field, const QVariant& value, int relation) { if (d->copySchema) { KexiDB::Field *fld = d->copySchema->findTableField(field); if (fld) { d->copySchema->addToWhereExpression(fld, value, relation); } } else { kDebug() << "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() ) { d->cursor = d->connection->prepareQuery("SELECT '' AS expr1 FROM kexi__db WHERE kexi__db.db_property = 'kexidb_major_ver'"); } else if ( d->copySchema) { kDebug() << "Opening cursor.." << d->copySchema->debugString(); d->cursor = d->connection->prepareQuery(*d->copySchema, KexiDB::Cursor::Buffered); } if (d->cursor) { bool ok = d->view->setData(d->cursor); if (ok) { kDebug() << "Moving to first record.."; if (!d->cursor->moveFirst()) { ok = !d->cursor->error(); } } return ok; } } return false; } bool KexiDBReportData::close() { if ( d->cursor ) { d->cursor->close(); delete d->cursor; d->cursor = 0; } return true; } bool KexiDBReportData::getSchema(const QString& partClass) { if (d->connection) { delete d->originalSchema; d->originalSchema = 0; delete d->copySchema; d->copySchema = 0; if ((partClass.isEmpty() || partClass == "org.kexi-project.table") && d->connection->tableSchema(d->objectName)) { kDebug() << d->objectName << "is a table.."; d->originalSchema = new KexiDB::QuerySchema(*(d->connection->tableSchema(d->objectName))); } else if ((partClass.isEmpty() || partClass == "org.kexi-project.query") && d->connection->querySchema(d->objectName)) { kDebug() << d->objectName << "is a query.."; d->connection->querySchema(d->objectName)->debug(); d->originalSchema = new KexiDB::QuerySchema(*(d->connection->querySchema(d->objectName))); } if (d->originalSchema) { kDebug() << "Original:" << d->connection->selectStatement(*d->originalSchema); d->originalSchema->debug(); d->copySchema = new KexiDB::QuerySchema(*d->originalSchema); d->copySchema->debug(); kDebug() << "Copy:" << d->connection->selectStatement(*d->copySchema); } 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 KexiDB::QueryColumnInfo::Vector fieldsExpanded( d->cursor->query()->fieldsExpanded(KexiDB::QuerySchema::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 KexiDB::QueryColumnInfo::Vector fieldsExpanded( d->originalSchema->fieldsExpanded(KexiDB::QuerySchema::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 { if ( d->cursor ) return d->cursor->value ( i ); return QVariant(); } QVariant KexiDBReportData::value ( const QString &fld ) const { int i = fieldNumber ( fld ); if ( d->cursor ) 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 KexiDB::rowCount ( *d->copySchema ); } else { return 1; } } QStringList KexiDBReportData::scriptList(const QString& interpreter) const { QStringList scripts; if( d->connection) { QList scriptids = d->connection->objectIds(KexiPart::ScriptObjectType); QStringList scriptnames = d->connection->objectNames(KexiPart::ScriptObjectType); QString script; int i; i = 0; kDebug() << scriptids << scriptnames; kDebug() << interpreter; //A blank entry scripts << ""; foreach(int id, scriptids) { kDebug() << "ID:" << id; tristate res; 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 (interpreter == scriptelem.attribute("language") && scriptelem.attribute("scripttype") == "object") { scripts << scriptnames[i]; } } else { kDebug() << "Unable to parse script"; } } else { kDebug() << "Unable to loadDataBlock"; } ++i; } kDebug() << scripts; } return scripts; } QString KexiDBReportData::scriptCode(const QString& scriptname, const QString& language) const { QString scripts; if (d->connection) { QList scriptids = d->connection->objectIds(KexiPart::ScriptObjectType); QStringList scriptnames = d->connection->objectNames(KexiPart::ScriptObjectType); int i = 0; QString script; foreach(int id, scriptids) { kDebug() << "ID:" << id; tristate res; res = d->connection->loadDataBlock(id, script, QString()); if (res == true) { QDomDocument domdoc; bool parsed = domdoc.setContent(script, false); if (! parsed) { kDebug() << "XML parsing error"; return QString(); } QDomElement scriptelem = domdoc.namedItem("script").toElement(); if (scriptelem.isNull()) { kDebug() << "script domelement is null"; return QString(); } QString interpretername = scriptelem.attribute("language"); kDebug() << language << interpretername; kDebug() << scriptelem.attribute("scripttype"); kDebug() << scriptname << scriptnames[i]; if (language == interpretername && (scriptelem.attribute("scripttype") == "module" || scriptname == scriptnames[i])) { scripts += '\n' + scriptelem.text().toUtf8(); } ++i; } else { kDebug() << "Unable to loadDataBlock"; } } } return scripts; } QStringList KexiDBReportData::dataSources() 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) { KexiDB::TableSchema* 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) { KexiDB::QuerySchema* qsc = d->connection->querySchema(qids[i]); if (qsc) qs << qsc->name(); } } return qs; } -KoReportData* KexiDBReportData::create(const QString& source) +KoReportData* KexiDBReportData::create(const QString& source) const { return new KexiDBReportData(source, d->connection, d->view); } diff --git a/kexi/plugins/reports/kexidbreportdata.h b/kexi/plugins/reports/kexidbreportdata.h index 4b9dcb95627..7fb20c22e55 100644 --- a/kexi/plugins/reports/kexidbreportdata.h +++ b/kexi/plugins/reports/kexidbreportdata.h @@ -1,84 +1,84 @@ /* * Kexi Report Plugin * Copyright (C) 2007-2009 by Adam Pigg (adam@piggz.co.uk) * Copyright (C) 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 __KEXIDBREPORTDATA_H__ #define __KEXIDBREPORTDATA_H__ #include #include #include #include #include class KexiReportView; /** */ class KexiDBReportData : public KoReportData { public: KexiDBReportData(const QString &objectName, KexiDB::Connection *conn, KexiReportView *view); /*! * @a partClass specifies @a objectName type: 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& partClass, KexiDB::Connection *conn, KexiReportView *view); virtual ~KexiDBReportData(); virtual QStringList fieldNames() const; virtual void setSorting(const QList& sorting); virtual void addExpression(const QString &field, const QVariant &value, int relation = '='); virtual QString sourceName() const; virtual int fieldNumber(const QString &field) const; virtual QVariant value(unsigned 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 QString& language) const; virtual QString scriptCode(const QString& script, const QString& language) const; virtual QStringList dataSources() const; - virtual KoReportData* create(const QString &source); + virtual KoReportData* create(const QString &source) const; private: class Private; Private * const d; bool getSchema(const QString& partClass = QString()); }; #endif diff --git a/libs/koreport/common/KoReportData.cpp b/libs/koreport/common/KoReportData.cpp index aa620d055d0..4586b4dcf69 100644 --- a/libs/koreport/common/KoReportData.cpp +++ b/libs/koreport/common/KoReportData.cpp @@ -1,80 +1,80 @@ /* Calligra/Kexi report engine * Copyright (C) 2007-2010 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 "KoReportData.h" #include KoReportData::~KoReportData() { } KoReportData::SortedField::SortedField() : order(Qt::AscendingOrder) { } QStringList KoReportData::fieldKeys() const { return fieldNames(); } QString KoReportData::sourceName() const { return QString(); } void KoReportData::setSorting(const QList &sorting) { Q_UNUSED(sorting); } void KoReportData::addExpression(const QString &field, const QVariant &value, int relation) { Q_UNUSED(field); Q_UNUSED(value); Q_UNUSED(relation); } QStringList KoReportData::scriptList(const QString &language) const { Q_UNUSED(language); return QStringList(); } QString KoReportData::scriptCode(const QString &script, const QString &language) const { Q_UNUSED(script); Q_UNUSED(language); return QString(); } QStringList KoReportData::dataSources() const { return QStringList(); } QStringList KoReportData::dataSourceNames() const { return dataSources(); } -KoReportData* KoReportData::create(const QString &source) +KoReportData* KoReportData::create(const QString &source) const { Q_UNUSED(source); return 0; } diff --git a/libs/koreport/common/KoReportData.h b/libs/koreport/common/KoReportData.h index e7f744fd182..aa32fb42e1f 100644 --- a/libs/koreport/common/KoReportData.h +++ b/libs/koreport/common/KoReportData.h @@ -1,116 +1,116 @@ /* Calligra/Kexi report engine * Copyright (C) 2007-2010 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 __KOREPORTDATA_H__ #define __KOREPORTDATA_H__ #include "koreport_export.h" #include /** */ class KOREPORT_EXPORT KoReportData { public: virtual ~KoReportData(); //! Describes sorting for single field /*! By default the order is ascending. */ class KOREPORT_EXPORT SortedField { public: SortedField(); QString field; Qt::SortOrder order; }; //!Open the dataset virtual bool open() = 0; //!Close the dataset virtual bool close() = 0; //!Move to the next record virtual bool moveNext() = 0; //!Move to the previous record virtual bool movePrevious() = 0; //!Move to the first record virtual bool moveFirst() = 0; //!Move to the last record virtual bool moveLast() = 0; //!Return the current position in the dataset virtual qint64 at() const = 0; //!Return the total number of records virtual qint64 recordCount() const = 0; //!Return the index number of the field given by nane field virtual int fieldNumber(const QString &field) const = 0; //!Return the list of field names virtual QStringList fieldNames() const = 0; //!Return the list of field keys. Returns fieldNames() by default virtual QStringList fieldKeys() const; //!Return the value of the field at the given position for the current record virtual QVariant value(unsigned int) const = 0; //!Return the value of the field fir the given name for the current record virtual QVariant value(const QString &field) const = 0; //!Return the name of this source virtual QString sourceName() const; //!Sets the sorting for the data //!Should be called before open() so that the data source can be edited accordingly //!Default impl does nothing virtual void setSorting(const QList &sorting); /** @brief Adds an expression to the data source */ virtual void addExpression(const QString &field, const QVariant &value, int relation = '='); //!Utility Functions //!TODO These are probably eligable to be moved into a new class //!Allow the reportdata implementation to return a list of possible scripts for a given language virtual QStringList scriptList(const QString& language) const; //!Allow the reportdata implementation to return some script code based on a specific script name //!and a language, as set in the report virtual QString scriptCode(const QString& script, const QString& language) const; //!Return a list of data sources possible for advanced controls virtual QStringList dataSources() const; //!Return a list of data source names possible for advanced controls. //!Returns dataSources() by default virtual QStringList dataSourceNames() const; //! Creates a new instance with data source. Default implementation returns @c nullptr. //! @a source is a driver-specific identifier. //! Owner of the returned pointer is the caller. - virtual KoReportData* create(const QString &source) Q_REQUIRED_RESULT; + virtual KoReportData* create(const QString &source) const Q_REQUIRED_RESULT; }; #endif diff --git a/libs/koreport/common/KoReportItemBase.h b/libs/koreport/common/KoReportItemBase.h index d1b48e6a762..359d13bdd3d 100644 --- a/libs/koreport/common/KoReportItemBase.h +++ b/libs/koreport/common/KoReportItemBase.h @@ -1,139 +1,139 @@ /* * KoReport Library * Copyright (C) 2007-2010 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 KOREPORTITEMBASE_H #define KOREPORTITEMBASE_H #include #include #include #include #include #include "koreport_export.h" #include "krpos.h" #include "krsize.h" class OROPage; class OROSection; class KRSize; class KRScriptHandler; class KoReportData; namespace KoProperty { class Set; class Property; } class KRTextStyleData { public: QFont font; Qt::Alignment alignment; QColor backgroundColor; QColor foregroundColor; int backgroundOpacity; }; class KRLineStyleData { public: int weight; QColor lineColor; Qt::PenStyle style; }; /** @author */ class KOREPORT_EXPORT KoReportItemBase : public QObject { Q_OBJECT public: KoReportItemBase(); virtual ~KoReportItemBase(); /** @brief Return the item type as a string. Required by all items @return Item type */ virtual QString typeName() const = 0; /** @brief Render the item into a primitive which is used by the second stage renderer @return the height required by the object */ virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KRScriptHandler *script); /** @brief Render a complex item that uses a sub query as a data source @return the height required by the object */ virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KoReportData *data, KRScriptHandler *script); /** @brief Override if the item supports a simple data source, such as a field @return The field name or expression for the data source */ virtual QString itemDataSource() const; /** @brief Override if the item uses a sub query and linked fields, such as a chart or sub-report @return True if uses a sub query */ - virtual bool supportsSubQuery(); + virtual bool supportsSubQuery() const; KoProperty::Set* propertySet() const; KRPos position(); void setEntityName(const QString& n); QString entityName(); virtual void setUnit(const KoUnit& u); KRPos position() const; KRSize size() const; qreal Z; protected: KoProperty::Set *m_set; KoProperty::Property *m_name; KRPos m_pos; KRSize m_size; QString m_oldName; void addDefaultProperties(); virtual void createProperties() = 0; static bool parseReportRect(const QDomElement &, KRPos *pos, KRSize *siz); static bool parseReportTextStyleData(const QDomElement &, KRTextStyleData &); static bool parseReportLineStyleData(const QDomElement &, KRLineStyleData &); }; #endif diff --git a/libs/koreport/wrtembed/KoReportDesigner.h b/libs/koreport/wrtembed/KoReportDesigner.h index 1d06cf2f41c..28cbe24c333 100644 --- a/libs/koreport/wrtembed/KoReportDesigner.h +++ b/libs/koreport/wrtembed/KoReportDesigner.h @@ -1,386 +1,386 @@ /* * OpenRPT report writer and rendering engine * Copyright (C) 2001-2007 by OpenMFG, LLC * Copyright (C) 2007-2008 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 REPORTDESIGNER_H #define REPORTDESIGNER_H #include #include #include #include #include #include #include #include #include #include #include #include "koreport_export.h" #include "KoReportData.h" class ReportGridOptions; class QDomDocument; class QGraphicsScene; class QActionGroup; class KoRuler; class KoZoomHandler; class QGridLayout; class ReportSectionDetail; class ReportSection; class KoUnit; class ReportScene; class QGraphicsSceneMouseEvent; class QGraphicsSceneContextMenuEvent; class ReportSceneView; class ReportWriterSectionData; class KoReportPluginInterface; class KoReportPluginManager; // // Class ReportDesigner // The ReportDesigner is the main widget for designing a report // class KOREPORT_EXPORT KoReportDesigner : public QWidget { Q_OBJECT public: qreal m_pressX; qreal m_pressY; qreal m_releaseX; qreal m_releaseY; /** @brief Constructor that create a blank designer @param widget QWidget parent */ explicit KoReportDesigner(QWidget *); /** @brief Constructor that create a designer, and loads the report described in the QDomElement @param widget QWidget parent @param element Report structure XML element */ KoReportDesigner(QWidget *, const QDomElement &data); /** @brief Desctructor */ ~KoReportDesigner(); /** @brief Sets the report data The report data interface contains functions to retrieve data and information about the fields. @param kodata Pointer to KoReportData instance */ void setReportData(KoReportData* kodata); /** @brief Return a pointer to the reports data @return Pointer to report data */ - KoReportData *reportData(){return m_kordata;} + const KoReportData *reportData() const { return m_kordata; } /** @brief Return a pointer to the section specified @param section KRSectionData::Section enum value of the section to return @return Pointer to report section object, or 0 if no section exists */ ReportSection* section(KRSectionData::Section) const; /** @brief Deletes the section specified @param section KRSectionData::Section enum value of the section to return */ void removeSection(KRSectionData::Section); /** @brief Create a new section and insert it into the report @param section KRSectionData::Section enum value of the section to return */ void insertSection(KRSectionData::Section); /** @brief Return a pointer to the detail section. The detail section contains the actual detail section and related group sections @return Pointer to detail section */ ReportSectionDetail* detailSection() const { return m_detail; } /** @brief Sets the title of the reportData @param title Report Title */ void setReportTitle(const QString &); /** @brief Sets the parameters for the display of the background gridpoints @param visible Grid visibility @param divisions Number of minor divisions between major points */ void setGridOptions(bool visible, int divisions); /** @brief Return the title of the report */ QString reportTitle() const; /** @brief Return an XML description of the report @return QDomElement describing the report definition */ QDomElement document() const; /** @brief Return true if the design has been modified @return modified status */ bool isModified() const; /** @return a list of field names in the selected KoReportData */ QStringList fieldNames() const; /** @return a list of field keys in the selected KoReportData The keys can be used to reference the names */ QStringList fieldKeys() const; /** @brief Calculate the width of the page in pixels given the paper size, orientation, dpi and margin @return integer value of width in pixels */ int pageWidthPx() const; /** @return the scene (section) that is currently active */ QGraphicsScene* activeScene() const; /** @brief Sets the active Scene @param scene The scene to make active */ void setActiveScene(QGraphicsScene* scene); /** @return the property set for the general report properties */ KoProperty::Set* propertySet() const { return m_set; } /** @brief Give a hint on the size of the widget */ virtual QSize sizeHint() const; /** @brief Return a pointer to the zoom handler */ KoZoomHandler* zoomHandler() const; /** @brief Return the current unit assigned to the report */ KoUnit pageUnit() const; /** @brief Handle the context menu event for a report section @param scene The associated scene (section) */ void sectionContextMenuEvent(ReportScene *, QGraphicsSceneContextMenuEvent * e); /** @brief Handle the mouse release event for a report section */ void sectionMouseReleaseEvent(ReportSceneView *, QMouseEvent * e); void sectionMousePressEvent(ReportSceneView *, QMouseEvent * e); /** @brief Sets the property set for the currently selected item @param set Property set of item */ void changeSet(KoProperty::Set *); /** @brief Return the property set for the curently selected item */ KoProperty::Set* itemPropertySet() const { return m_itmset; } /** @brief Sets the modified status, defaulting to true for modified @param modified Modified status */ void setModified(bool = true); /** @brief Return a unique name that can be used by the entity @param entity Name of entity */ QString suggestEntityName(const QString &) const; /** @brief Checks if the supplied name is unique among all entities */ bool isEntityNameUnique(const QString &, KoReportItemBase* = 0) const; /** @brief Returns a list of actions that represent the entities that can be inserted into the report. Actions are created as children of @a group and belong to the group. @return list of actions */ static QList actions(QActionGroup* group); /** @return X position of mouse when mouse press occurs */ qreal getSelectionPressX() const; /** @return Y position of mouse when mouse press occurs */ qreal getSelectionPressY() const; /** @return difference between X position of mouse release and press */ qreal countSelectionWidth() const; /** @return difference between Y position of mouse release and press */ qreal countSelectionHeight() const; /** @return point that contains X,Y coordinates of mouse press */ QPointF getPressPoint() const; /** @return point that contains X,Y coordinates of mouse press */ QPointF getReleasePoint() const; public Q_SLOTS: void slotEditDelete(); void slotEditCut(); void slotEditCopy(); void slotEditPaste(); void slotEditPaste(QGraphicsScene *); void slotItem(const QString&); void slotSectionEditor(); void slotRaiseSelected(); void slotLowerSelected(); protected: ReportSection *m_reportHeader; ReportSection *m_pageHeaderFirst; ReportSection *m_pageHeaderOdd; ReportSection *m_pageHeaderEven; ReportSection *m_pageHeaderLast; ReportSection *m_pageHeaderAny; ReportSection *m_pageFooterFirst; ReportSection *m_pageFooterOdd; ReportSection *m_pageFooterEven; ReportSection *m_pageFooterLast; ReportSection *m_pageFooterAny; ReportSection *m_reportFooter; ReportSectionDetail *m_detail; private: class Private; Private * const d; void init(); bool m_modified; // true if this document has been modified, false otherwise KoReportData *m_kordata; /** @brief Sets the detail section to the given section */ void setDetail(ReportSectionDetail *rsd); /** @brief Deletes the detail section */ void deleteDetail(); virtual void resizeEvent(QResizeEvent * event); //Properties void createProperties(); KoProperty::Set* m_set; KoProperty::Set* m_itmset; KoProperty::Property* m_title; KoProperty::Property* m_pageSize; KoProperty::Property* m_orientation; KoProperty::Property* m_unit; KoProperty::Property* m_customHeight; KoProperty::Property* m_customWidth; KoProperty::Property* m_leftMargin; KoProperty::Property* m_rightMargin; KoProperty::Property* m_topMargin; KoProperty::Property* m_bottomMargin; KoProperty::Property* m_showGrid; KoProperty::Property* m_gridDivisions; KoProperty::Property* m_gridSnap; KoProperty::Property* m_labelType; KoProperty::Property* m_interpreter; KoProperty::Property* m_script; ReportWriterSectionData *m_sectionData; unsigned int selectionCount() const; void setSectionCursor(const QCursor&); void unsetSectionCursor(); private Q_SLOTS: void slotPropertyChanged(KoProperty::Set &s, KoProperty::Property &p); /** @brief When the 'page' button in the top left is pressed, change the property set to the reports properties. */ void slotPageButton_Pressed(); Q_SIGNALS: void pagePropertyChanged(KoProperty::Set &s); void propertySetChanged(); void dirty(); void reportDataChanged(); void itemInserted(const QString& entity); }; #endif diff --git a/plugins/reporting/chart/KoReportItemChart.cpp b/plugins/reporting/chart/KoReportItemChart.cpp index d68cb2b6f67..6db2a693975 100644 --- a/plugins/reporting/chart/KoReportItemChart.cpp +++ b/plugins/reporting/chart/KoReportItemChart.cpp @@ -1,435 +1,435 @@ /* * Kexi Report Plugin * Copyright (C) 2007-2010 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 "KoReportItemChart.h" #include #include #include #include #include "renderobjects.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef QVector datalist; KoReportItemChart::KoReportItemChart() { m_reportData = 0; createProperties(); } KoReportItemChart::KoReportItemChart(QDomNode & element) { m_reportData = 0; createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; QDomElement e = element.toElement(); m_name->setValue(e.attribute("report:name")); m_dataSource->setValue(e.attribute("report:data-source")); Z = e.attribute("report:z-index").toDouble(); m_chartType->setValue(e.attribute("report:chart-type").toInt()); m_chartSubType->setValue(e.attribute("report:chart-sub-type").toInt()); m_threeD->setValue(e.attribute("report:three-dimensions")); m_colorScheme->setValue(e.attribute("report:chart-color-scheme")); m_aa->setValue(e.attribute("report:antialiased")); m_xTitle->setValue(e.attribute("report:title-x-axis")); m_yTitle->setValue(e.attribute("report:title-y-axis")); m_backgroundColor->setValue(e.attribute("report:background-color")); m_displayLegend->setValue(e.attribute("report:display-legend")); m_legendPosition->setValue(e.attribute("report:legend-position")); m_legendOrientation->setValue(e.attribute("report:legend-orientation")); m_linkMaster->setValue(e.attribute("report:link-master")); m_linkChild->setValue(e.attribute("report:link-child")); parseReportRect(e, &m_pos, &m_size); } KoReportItemChart::~KoReportItemChart() { delete m_set; } void KoReportItemChart::createProperties() { m_chartWidget = 0; m_set = new KoProperty::Set(0, "Chart"); QStringList strings; QList keys; QStringList stringkeys; m_dataSource = new KoProperty::Property("data-source", QStringList(), QStringList(), QString(), i18n("Data Source")); m_dataSource->setOption("extraValueAllowed", "true"); m_font = new KoProperty::Property("Font", KGlobalSettings::generalFont(), i18n("Font"), i18n("Field Font")); keys << 1 << 2 << 3 << 4 << 5; strings << i18n("Bar") << i18n("Line") << i18n("Pie") << i18n("Ring") << i18n("Polar"); KoProperty::Property::ListData *typeData = new KoProperty::Property::ListData(keys, strings); m_chartType = new KoProperty::Property("chart-type", typeData, 1, i18n("Chart Type")); keys.clear(); strings.clear(); keys << 0 << 1 << 2 << 3; strings << i18n("Normal") << i18n("Stacked") << i18n("Percent") << i18n("Rows"); KoProperty::Property::ListData *subData = new KoProperty::Property::ListData(keys, strings); m_chartSubType = new KoProperty::Property("chart-sub-type", subData, 0, i18n("Chart Sub Type")); keys.clear(); strings.clear(); stringkeys << "default" << "rainbow" << "subdued"; strings << i18n("Default") << i18n("Rainbow") << i18n("Subdued"); m_colorScheme = new KoProperty::Property("chart-color-scheme", stringkeys, strings, "default", i18n("Color Scheme")); m_threeD = new KoProperty::Property("three-dimensions", QVariant(false), i18nc("Three dimensions", "3D")); m_aa = new KoProperty::Property("antialiased", QVariant(false), i18n("Antialiased")); m_xTitle = new KoProperty::Property("title-x-axis", QString(), i18n("X Axis Title"), i18n("X Axis Title")); m_yTitle = new KoProperty::Property("title-y-axis", QString(), i18n("Y Axis Title"), i18n("Y Axis Title")); m_displayLegend = new KoProperty::Property("display-legend", true, i18n("Display Legend"), i18n("Display Legend")); keys.clear(); strings.clear(); keys << (int)KDChartEnums::PositionNorth << (int)KDChartEnums::PositionEast << (int)KDChartEnums::PositionSouth << (int)KDChartEnums::PositionWest; QStringList names = KDChart::Position::printableNames(); foreach (const QVariant &pos, keys) { strings << names[pos.toInt()-1]; } subData = new KoProperty::Property::ListData(keys, strings); m_legendPosition = new KoProperty::Property("legend-position", subData, (int)KDChartEnums::PositionEast, i18n("Legend Position")); keys.clear(); strings.clear(); keys << Qt::Horizontal << Qt::Vertical; strings << i18n("Horizontal") << i18n("Vertical"); subData = new KoProperty::Property::ListData(keys, strings); m_legendOrientation = new KoProperty::Property("legend-orientation", subData, Qt::Vertical, i18n("Legend Orientation")); m_backgroundColor = new KoProperty::Property("background-color", Qt::white, i18n("Background Color"), i18n("Background Color")); m_linkMaster = new KoProperty::Property("link-master", QString(), i18n("Link Master"), i18n("Fields from master data source")); m_linkChild = new KoProperty::Property("link-child", QString(), i18n("Link Child"), i18n("Fields from child data source")); addDefaultProperties(); m_set->addProperty(m_dataSource); m_set->addProperty(m_chartType); m_set->addProperty(m_chartSubType); m_set->addProperty(m_font); m_set->addProperty(m_colorScheme); m_set->addProperty(m_threeD); m_set->addProperty(m_aa); m_set->addProperty(m_xTitle); m_set->addProperty(m_yTitle); m_set->addProperty(m_backgroundColor); m_set->addProperty(m_displayLegend); m_set->addProperty(m_legendPosition); m_set->addProperty(m_legendOrientation); m_set->addProperty(m_linkMaster); m_set->addProperty(m_linkChild); set3D(false); setAA(false); setColorScheme("default"); } void KoReportItemChart::set3D(bool td) { if (m_chartWidget && m_chartWidget->barDiagram()) { KDChart::BarDiagram *bar = m_chartWidget->barDiagram(); bar->setPen(QPen(Qt::black)); KDChart::ThreeDBarAttributes threed = bar->threeDBarAttributes(); threed.setEnabled(td); threed.setDepth(10); threed.setAngle(15); threed.setUseShadowColors(true); bar->setThreeDBarAttributes(threed); } } void KoReportItemChart::setAA(bool aa) { if (m_chartWidget && m_chartWidget->diagram()) { m_chartWidget->diagram()->setAntiAliasing(aa); } } void KoReportItemChart::setColorScheme(const QString &cs) { if (m_chartWidget && m_chartWidget->diagram()) { if (cs == "rainbow") { m_chartWidget->diagram()->useRainbowColors(); } else if (cs == "subdued") { m_chartWidget->diagram()->useSubduedColors(); } else { m_chartWidget->diagram()->useDefaultColors(); } } } -void KoReportItemChart::setConnection(KoReportData *c) +void KoReportItemChart::setConnection(const KoReportData *c) { m_reportData = c; populateData(); } void KoReportItemChart::populateData() { QVector data; QStringList labels; QStringList fn; delete m_chartWidget; m_chartWidget = 0; if (m_reportData) { QString src = m_dataSource->value().toString(); if (!src.isEmpty()) { KoReportData *curs = m_reportData->create(src); if (curs) { const QStringList keys = m_links.keys(); foreach(const QString& field, keys) { kDebug() << "Adding Expression:" << field << m_links[field]; curs->addExpression(field, m_links[field], '='); } } if (curs && curs->open()) { fn = curs->fieldNames(); //resize the data lists to match the number of columns int cols = fn.count() - 1; if ( cols > 0 ) { data.resize(cols); } m_chartWidget = new KDChart::Widget(); //_chartWidget->setStyle ( new QMotifStyle() ); m_chartWidget->setType((KDChart::Widget::ChartType) m_chartType->value().toInt()); m_chartWidget->setSubType((KDChart::Widget::SubType) m_chartSubType->value().toInt()); set3D(m_threeD->value().toBool()); setAA(m_aa->value().toBool()); setColorScheme(m_colorScheme->value().toString()); setBackgroundColor(m_backgroundColor->value().value()); curs->moveFirst(); //bool status = true; do { labels << curs->value(0).toString(); for (int i = 1; i <= cols; ++i) { data[i - 1] << curs->value(i).toDouble(); } } while (curs->moveNext()); for (int i = 1; i <= cols; ++i) { m_chartWidget->setDataset(i - 1, data[i - 1], fn[i]); } setLegend(m_displayLegend->value().toBool(), fn); //Add the axis setAxis(m_xTitle->value().toString(), m_yTitle->value().toString()); //Add the bottom labels if (m_chartWidget->barDiagram() || m_chartWidget->lineDiagram()) { KDChart::AbstractCartesianDiagram *dia = static_cast(m_chartWidget->diagram()); foreach(KDChart::CartesianAxis* axis, dia->axes()) { if (axis->position() == KDChart::CartesianAxis::Bottom) { axis->setLabels(labels); } } } } else { kDebug() << "Unable to open data set"; } delete curs; curs = 0; } else { kDebug() << "No source set"; } } else { kDebug() << "No connection!"; } } QStringList KoReportItemChart::masterFields() { return m_linkMaster->value().toString().split(','); } void KoReportItemChart::setLinkData(QString fld, QVariant val) { kDebug() << "Field: " << fld << "is" << val; m_links[fld] = val; } void KoReportItemChart::setAxis(const QString& xa, const QString &ya) { if (!m_chartWidget) { return; } Q_ASSERT(m_chartWidget); if (m_chartWidget->barDiagram() || m_chartWidget->lineDiagram()) { KDChart::AbstractCartesianDiagram *dia = static_cast(m_chartWidget->diagram()); KDChart::CartesianAxis *xAxis = 0; KDChart::CartesianAxis *yAxis = 0; //delete existing axis foreach(KDChart::CartesianAxis* axis, dia->axes()) { if (axis->position() == KDChart::CartesianAxis::Bottom) { xAxis = axis; } if (axis->position() == KDChart::CartesianAxis::Left) { yAxis = axis; } } if (!xAxis) { xAxis = new KDChart::CartesianAxis(static_cast(m_chartWidget->diagram())); xAxis->setPosition(KDChart::CartesianAxis::Bottom); dia->addAxis(xAxis); } if (!yAxis) { yAxis = new KDChart::CartesianAxis(static_cast(m_chartWidget->diagram())); yAxis->setPosition(KDChart::CartesianAxis::Left); dia->addAxis(yAxis); } xAxis->setTitleText(xa); yAxis->setTitleText(ya); } } void KoReportItemChart::setBackgroundColor(const QColor&) { //Set the background color if (!m_chartWidget) { return; } KDChart::Chart *cht = m_chartWidget->diagram()->coordinatePlane()->parent(); KDChart::BackgroundAttributes ba; ba.setVisible(true); ba.setBrush(m_backgroundColor->value().value()); cht->setBackgroundAttributes(ba); } void KoReportItemChart::setLegend(bool le, const QStringList &legends) { //Add the legend if (m_chartWidget) { if (le && ! legends.isEmpty()) { m_chartWidget->addLegend(KDChart::Position((KDChartEnums::PositionValue)m_legendPosition->value().toInt())); m_chartWidget->legend()->setOrientation((Qt::Orientation) m_legendOrientation->value().toInt()); m_chartWidget->legend()->setTitleText("Legend"); for (uint i = 1; i < (uint)legends.count(); ++i) { m_chartWidget->legend()->setText(i - 1, legends[i]); } m_chartWidget->legend()->setShowLines(true); } else { if (m_chartWidget->legend()) { m_chartWidget->takeLegend(m_chartWidget->legend()); } } } } // RTTI QString KoReportItemChart::typeName() const { return "chart"; } int KoReportItemChart::renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KoReportData *data, KRScriptHandler *script) { Q_UNUSED(script); setConnection(data); QStringList masters = masterFields(); for (int i = 0; i < masters.size(); ++i) { if (!masters[i].simplified().isEmpty()) { setLinkData(masters[i], data->value(masters[i])); } } populateData(); if (widget()) { OROPicture * pic = new OROPicture(); widget()->setFixedSize(m_size.toScene().toSize()); QPainter p(pic->picture()); widget()->diagram()->coordinatePlane()->parent()->paint(&p, QRect(QPoint(0, 0), m_size.toScene().toSize())); QPointF pos = m_pos.toScene(); QSizeF size = m_size.toScene(); pos += offset; pic->setPosition(pos); pic->setSize(size); if (page) page->addPrimitive(pic); OROPicture *p2 = static_cast(pic->clone()); p2->setPosition(m_pos.toPoint()); if (section) section->addPrimitive(p2); } return 0; } diff --git a/plugins/reporting/chart/KoReportItemChart.h b/plugins/reporting/chart/KoReportItemChart.h index 1cf91a1bf7e..57313ee31b8 100644 --- a/plugins/reporting/chart/KoReportItemChart.h +++ b/plugins/reporting/chart/KoReportItemChart.h @@ -1,118 +1,118 @@ /* * 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 KRCHARTDATA_H #define KRCHARTDATA_H #include "KoReportItemBase.h" #include #include #include "krsize.h" #include "krpos.h" #include #include "KoReportData.h" /** @author Adam Pigg */ namespace Scripting { class Chart; } class KoReportItemChart : public KoReportItemBase { public: KoReportItemChart(); explicit KoReportItemChart(QDomNode &element); ~KoReportItemChart(); virtual QString typeName() const; virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KoReportData *data, KRScriptHandler *script); KDChart::Widget *widget() { return m_chartWidget; } /** @brief Perform the query for the chart and set the charts data */ void populateData(); - void setConnection(KoReportData*); + void setConnection(const KoReportData *c); /** @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(); /** @brief The chart object is a complex object that uses its own data source @return true */ virtual bool supportsSubQuery() { return true; } protected: KoProperty::Property * m_dataSource; KoProperty::Property * m_font; KoProperty::Property * m_chartType; KoProperty::Property * m_chartSubType; KoProperty::Property * m_threeD; KoProperty::Property * m_colorScheme; KoProperty::Property * m_aa; KoProperty::Property * m_xTitle; KoProperty::Property * m_yTitle; KoProperty::Property *m_backgroundColor; KoProperty::Property *m_displayLegend; KoProperty::Property *m_legendPosition; KoProperty::Property *m_legendOrientation; KoProperty::Property *m_linkMaster; KoProperty::Property *m_linkChild; KDChart::Widget *m_chartWidget; void set3D(bool); void setAA(bool); void setColorScheme(const QString &); void setAxis(const QString&, const QString&); void setBackgroundColor(const QColor&); void setLegend(bool, const QStringList &legends = QStringList()); private: virtual void createProperties(); - KoReportData *m_reportData; + const KoReportData *m_reportData; friend class Scripting::Chart; QMap m_links; //Map of field->value for child/master links }; #endif