KReport

KReportDataSource.h
1/* This file is part of the KDE project
2 * Copyright (C) 2007-2010 by Adam Pigg (adam@piggz.co.uk)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17#ifndef KREPORTDATA_H
18#define KREPORTDATA_H
19
20#include <QStringList>
21#include <QVariant>
22
23#include "kreport_export.h"
24#include "config-kreport.h"
25
26/*!
27 * @brief Abstraction of report data source.
28 *
29 * A data source provides data to the report engine, usually from a
30 * database, but could also be implemented for text and other file formats
31 */
32class KREPORT_EXPORT KReportDataSource
33{
34
35public:
37 virtual ~KReportDataSource();
38
39 /*!
40 * @brief Describes sorting for single field,
41 * By default the order is ascending.
42 */
43 class KREPORT_EXPORT SortedField
44 {
45 public:
47 SortedField(const SortedField& other);
49 SortedField& operator=(const SortedField &other);
50 bool operator==(const SortedField &other) const;
51 bool operator!=(const SortedField &other) const;
52 void setField(const QString &field);
53 void setOrder(Qt::SortOrder order);
54 QString field() const;
55 Qt::SortOrder order() const;
56
57 private:
58 class Private;
59 Private * const d;
60 };
61
62 //! Open the dataset
63 virtual bool open() = 0;
64
65 //! Close the dataset
66 virtual bool close() = 0;
67
68 //! Move to the next record
69 virtual bool moveNext() = 0;
70
71 //! Move to the previous record
72 virtual bool movePrevious() = 0;
73
74 //! Move to the first record
75 virtual bool moveFirst() = 0;
76
77 //! Move to the last record
78 virtual bool moveLast() = 0;
79
80 //! Return the current position in the dataset
81 virtual qint64 at() const = 0;
82
83 //! Return the total number of records
84 virtual qint64 recordCount() const = 0;
85
86 //! Return the index number of the field given by nane field
87 virtual int fieldNumber(const QString &field) const = 0;
88
89 //! Return the list of field names
90 virtual QStringList fieldNames() const = 0;
91
92 //! Return the list of field keys. Returns fieldNames() by default
93 virtual QStringList fieldKeys() const;
94
95 //! Return the value of the field at the given position for the current record
96 virtual QVariant value(int pos) const = 0;
97
98 //! Return the value of the field fir the given name for the current record
99 virtual QVariant value(const QString &field) const = 0;
100
101 //! Return the name of this source
102 virtual QString sourceName() const;
103
104 //! @return the class name of this source
105 virtual QString sourceClass() const;
106
107 //! Sets the sorting for the data
108 //! Should be called before open() so that the data source can be edited accordingly
109 //! Default impl does nothing
110 virtual void setSorting(const QList<SortedField> &sorting);
111
112 //! Adds a condition to the data source
113 virtual void addCondition(const QString &field, const QVariant &value, const QString& relation = QLatin1String("="));
114
115 //! Return a list of data source names available for this data source
116 //! Works after the source is opened
117 virtual QStringList dataSourceNames() const = 0;
118
119 //! Return data source caption for specified @a dataSourceName
120 //! It is possibly translated. As such it is suitable for use in GUIs.
121 //! Default implementation just returns @a dataSourceName.
122 virtual QString dataSourceCaption(const QString &dataSourceName) const;
123
124 //! Creates a new instance with data source. Default implementation returns @c nullptr.
125 //! @a source is implementation-specific identifier.
126 //! Owner of the returned pointer is the caller.
127 Q_REQUIRED_RESULT virtual KReportDataSource* create(const QString &source) const;
128
129private:
130 Q_DISABLE_COPY(KReportDataSource)
131 class Private;
132 Private * const d;
133};
134
135#endif
Describes sorting for single field, By default the order is ascending.
Abstraction of report data source.
virtual bool close()=0
Close the dataset.
virtual bool moveNext()=0
Move to the next record.
virtual QVariant value(const QString &field) const =0
Return the value of the field fir the given name for the current record.
virtual bool moveLast()=0
Move to the last record.
virtual int fieldNumber(const QString &field) const =0
Return the index number of the field given by nane field.
virtual qint64 recordCount() const =0
Return the total number of records.
virtual bool movePrevious()=0
Move to the previous record.
virtual qint64 at() const =0
Return the current position in the dataset.
virtual bool open()=0
Open the dataset.
virtual bool moveFirst()=0
Move to the first record.
virtual QStringList fieldNames() const =0
Return the list of field names.
virtual QVariant value(int pos) const =0
Return the value of the field at the given position for the current record.
SortOrder
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.