diff --git a/src/common/KReportData.h b/src/common/KReportData.h
index 3b67e0d5..8b2704b1 100644
--- a/src/common/KReportData.h
+++ b/src/common/KReportData.h
@@ -1,123 +1,122 @@
/* This file is part of the KDE project
* 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 KREPORTDATA_H
#define KREPORTDATA_H
#include
#include
#include "kreport_export.h"
#include "config-kreport.h"
-/**
-
+/** @brief Abstraction of report data source
*/
class KREPORT_EXPORT KReportData
{
public:
virtual ~KReportData();
//! Describes sorting for single field
/*! By default the order is ascending. */
class KREPORT_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;
//! @return the class name of this source
virtual QString sourceClass() 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);
//! Adds an expression to the data source
virtual void addExpression(const QString &field, const QVariant &value, char relation = '=');
//! Utility Functions
//! @todo These are probably eligable to be moved into a new class
#ifdef KREPORT_SCRIPTING
//! Allow the reportdata implementation to return a list of possible scripts
virtual QStringList scriptList() const;
//! Allow the reportdata implementation to return some script code based on a specific script name
//! as set in the report
virtual QString scriptCode(const QString& script) const;
#endif
//! 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.
+ //! @a source is implementation-specific identifier.
//! Owner of the returned pointer is the caller.
virtual KReportData* create(const QString &source) const Q_REQUIRED_RESULT;
};
#endif
diff --git a/src/common/KReportPluginManager.cpp b/src/common/KReportPluginManager.cpp
index c0b57100..1f7112bc 100644
--- a/src/common/KReportPluginManager.cpp
+++ b/src/common/KReportPluginManager.cpp
@@ -1,301 +1,301 @@
/* This file is part of the KDE project
Copyright (C) 2010 by Adam Pigg (adam@piggz.co.uk)
Copyright (C) 2015-2016 Jarosław Staniek
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "KReportPluginManager.h"
#include "KReportPluginManagerPrivate.h"
#include "KReportPluginMetaData.h"
#include "KReportJsonTrader_p.h"
#include "KReportUtils_p.h"
#include "kreport_debug.h"
#include
//Include the static items
#include "../items/label/KReportLabelPlugin.h"
#include "../items/check/KReportCheckBoxPlugin.h"
#include "../items/field/KReportFieldPlugin.h"
#include "../items/image/KReportImagePlugin.h"
#include "../items/text/KReportTextPlugin.h"
KReportPluginManager::Private::Private(KReportPluginManager *qq)
: q(qq), m_parent(new QObject), m_findPlugins(true)
{
}
// ---
KReportPluginEntry::KReportPluginEntry()
: m_loader(0), m_interface(0), m_metaData(0)
{
}
KReportPluginEntry::KReportPluginEntry(KReportPluginInterface *staticInterface)
: m_loader(0), m_interface(staticInterface), m_metaData(0)
{
}
KReportPluginEntry::~KReportPluginEntry()
{
delete m_metaData;
delete m_interface;
}
KReportPluginInterface* KReportPluginEntry::plugin()
{
if (m_interface) {
return m_interface;
}
if (!m_loader) {
kreportWarning() << "No such plugin";
return 0;
}
if (!m_loader->load()) {
kreportWarning() << "Could not load plugin" << m_loader->fileName();
return 0;
}
KPluginFactory *factory = qobject_cast(m_loader->instance());
if (!factory) {
kreportWarning() << "Could not create factory for plugin" << m_loader->fileName();
return 0;
}
m_interface = factory->create();
if (!m_interface) {
kreportWarning() << "Could not create instance of plugin" << m_loader->fileName();
return 0;
}
m_interface->setMetaData(m_metaData);
return m_interface;
}
void KReportPluginEntry::setBuiltIn(bool set)
{
m_metaData->setBuiltIn(set);
}
void KReportPluginEntry::setStatic(bool set)
{
m_metaData->setStatic(set);
}
const KReportPluginMetaData *KReportPluginEntry::metaData() const
{
return m_metaData;
}
void KReportPluginEntry::setMetaData(KReportPluginMetaData *metaData)
{
delete m_metaData;
m_metaData = metaData;
if (m_interface) {
m_interface->setMetaData(m_metaData);
}
}
void KReportPluginEntry::setMetaData(const QJsonObject &metaData)
{
setMetaData(new KReportPluginMetaData(metaData));
}
void KReportPluginEntry::setMetaData(QPluginLoader *loader)
{
m_loader = loader;
setMetaData(new KReportPluginMetaData(*m_loader));
}
// ---
KReportPluginManager::Private::~Private()
{
delete m_parent;
}
template
void KReportPluginManager::Private::addBuiltInPlugin(const QJsonObject &json)
{
KReportPluginEntry *entry = new KReportPluginEntry(new PluginClass(m_parent));
QJsonObject j = json.value(QLatin1String("MetaData")).toObject();
//kreportDebug() << j;
entry->setMetaData(j);
entry->setBuiltIn(true);
if (entry->metaData()->id().isEmpty()) {
kreportWarning() << "Plugin" << entry->metaData()->name() << "has no identifier so won't be added to manager";
delete entry;
return;
}
entry->setStatic(true);
m_plugins.insert(entry->metaData()->id(), entry);
m_pluginsByLegacyName.insert(entry->metaData()->value(QLatin1String("X-KDE-PluginInfo-LegacyName"), entry->metaData()->id()), entry);
}
#define KREPORT_ADD_BUILTIN_PLUGIN(name) \
addBuiltInPlugin(KREPORT_STATIC_PLUGIN_METADATA(name))
QMap* KReportPluginManager::Private::plugins()
{
if (m_findPlugins) {
findPlugins();
}
return &m_plugins;
}
QMap* KReportPluginManager::Private::pluginsByLegacyName()
{
if (m_findPlugins) {
findPlugins();
}
return &m_pluginsByLegacyName;
}
void KReportPluginManager::Private::findPlugins()
{
KREPORT_ADD_BUILTIN_PLUGIN(KReportLabelPlugin);
KREPORT_ADD_BUILTIN_PLUGIN(KReportCheckBoxPlugin);
KREPORT_ADD_BUILTIN_PLUGIN(KReportFieldPlugin);
KREPORT_ADD_BUILTIN_PLUGIN(KReportImagePlugin);
KREPORT_ADD_BUILTIN_PLUGIN(KReportTextPlugin);
//kreportDebug() << "Load all plugins";
const QList offers = KReportJsonTrader::self()->query(QLatin1String("KReport/Element"));
const QString expectedVersion = QString::fromLatin1("%1.%2")
.arg(KREPORT_STABLE_VERSION_MAJOR).arg(KREPORT_STABLE_VERSION_MINOR);
foreach(QPluginLoader *loader, offers) {
//QJsonObject json = loader->metaData();
//kreportDebug() << json;
//! @todo check version
QScopedPointer entry(new KReportPluginEntry);
entry->setMetaData(loader);
const KReportPluginMetaData *metaData = entry->metaData();
if (metaData->version() != expectedVersion) {
- kreportWarning() << "Driver with ID" << metaData->id()
+ kreportWarning() << "KReport element plugin with ID" << metaData->id()
<< "(" << metaData->fileName() << ")"
<< "has version" << metaData->version() << "but expected version is"
<< expectedVersion
<< "-- skipping it";
continue;
}
if (m_plugins.contains(metaData->id())) {
kreportWarning() << "KReport element plugin with ID" << metaData->id()
<< "already found at"
<< m_plugins.value(metaData->id())->metaData()->fileName()
<< "-- skipping another at" << metaData->fileName();
continue;
}
if (!KReportPrivate::setupPrivateIconsResourceWithMessage(
QLatin1String(KREPORT_BASE_NAME_LOWER),
QString::fromLatin1("icons/%1_%2.rcc")
.arg(metaData->id()).arg(KReportPrivate::supportedIconTheme),
QtWarningMsg,
QString::fromLatin1(":/icons/%1").arg(metaData->id())))
{
continue;
}
addEntry(entry.take());
}
m_findPlugins = false;
}
void KReportPluginManager::Private::addEntry(KReportPluginEntry *entry)
{
m_plugins.insert(entry->metaData()->id(), entry);
const QString legacyName(entry->metaData()->value(QLatin1String("X-KDE-PluginInfo-LegacyName"), entry->metaData()->id()));
if (!legacyName.isEmpty() && entry->metaData()->id().startsWith(QLatin1String("org.kde.kreport"))) {
m_pluginsByLegacyName.insert(legacyName, entry);
}
}
// ---
//! Class for access to KReportPluginManager constructor
class KReportPluginManagerSingleton
{
public:
KReportPluginManager object;
};
KReportPluginManager::KReportPluginManager()
: d(new Private(this))
{
KReportPrivate::setupPrivateIconsResourceWithMessage(
QLatin1String(KREPORT_BASE_NAME_LOWER),
QString::fromLatin1("icons/kreport_%1.rcc").arg(KReportPrivate::supportedIconTheme), QtFatalMsg);
}
KReportPluginManager::~KReportPluginManager()
{
delete d;
}
Q_GLOBAL_STATIC(KReportPluginManagerSingleton, s_self)
KReportPluginManager* KReportPluginManager::self()
{
return &s_self->object;
}
QStringList KReportPluginManager::pluginIds() const
{
return d->plugins()->keys();
}
const KReportPluginMetaData *KReportPluginManager::pluginMetaData(const QString& id) const
{
KReportPluginEntry *entry = d->plugins()->value(id);
if (!entry) {
return 0;
}
return entry->metaData();
}
KReportPluginInterface* KReportPluginManager::plugin(const QString& id) const
{
KReportPluginEntry *entry;
entry = d->plugins()->value(id);
if (!entry) {
entry = d->pluginsByLegacyName()->value(id);
}
if (!entry) {
return 0;
}
return entry->plugin();
}
QList KReportPluginManager::createActions(QObject *parent)
{
Q_ASSERT(parent);
const QMap *plugins = d->plugins();
QList actList;
foreach(KReportPluginEntry* plugin, *plugins) {
const KReportPluginMetaData *metaData = plugin->metaData();
if (metaData) {
QAction *act = new QAction(QIcon::fromTheme(metaData->iconName()), metaData->name(), parent);
act->setObjectName(metaData->id());
act->setCheckable(true);
//Store the order priority in the user data field
act->setData(metaData->priority());
actList << act;
}
}
return actList;
}