File indexing completed on 2024-05-05 16:48:33
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007-2010 by Adam Pigg (adam@piggz.co.uk) 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public 0015 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0016 */ 0017 #ifndef KREPORTDATA_H 0018 #define KREPORTDATA_H 0019 0020 #include <QStringList> 0021 #include <QVariant> 0022 0023 #include "kreport_export.h" 0024 #include "config-kreport.h" 0025 0026 /*! 0027 * @brief Abstraction of report data source. 0028 * 0029 * A data source provides data to the report engine, usually from a 0030 * database, but could also be implemented for text and other file formats 0031 */ 0032 class KREPORT_EXPORT KReportDataSource 0033 { 0034 0035 public: 0036 KReportDataSource(); 0037 virtual ~KReportDataSource(); 0038 0039 /*! 0040 * @brief Describes sorting for single field, 0041 * By default the order is ascending. 0042 */ 0043 class KREPORT_EXPORT SortedField 0044 { 0045 public: 0046 SortedField(); 0047 SortedField(const SortedField& other); 0048 ~SortedField(); 0049 SortedField& operator=(const SortedField &other); 0050 bool operator==(const SortedField &other) const; 0051 bool operator!=(const SortedField &other) const; 0052 void setField(const QString &field); 0053 void setOrder(Qt::SortOrder order); 0054 QString field() const; 0055 Qt::SortOrder order() const; 0056 0057 private: 0058 class Private; 0059 Private * const d; 0060 }; 0061 0062 //! Open the dataset 0063 virtual bool open() = 0; 0064 0065 //! Close the dataset 0066 virtual bool close() = 0; 0067 0068 //! Move to the next record 0069 virtual bool moveNext() = 0; 0070 0071 //! Move to the previous record 0072 virtual bool movePrevious() = 0; 0073 0074 //! Move to the first record 0075 virtual bool moveFirst() = 0; 0076 0077 //! Move to the last record 0078 virtual bool moveLast() = 0; 0079 0080 //! Return the current position in the dataset 0081 virtual qint64 at() const = 0; 0082 0083 //! Return the total number of records 0084 virtual qint64 recordCount() const = 0; 0085 0086 //! Return the index number of the field given by nane field 0087 virtual int fieldNumber(const QString &field) const = 0; 0088 0089 //! Return the list of field names 0090 virtual QStringList fieldNames() const = 0; 0091 0092 //! Return the list of field keys. Returns fieldNames() by default 0093 virtual QStringList fieldKeys() const; 0094 0095 //! Return the value of the field at the given position for the current record 0096 virtual QVariant value(int pos) const = 0; 0097 0098 //! Return the value of the field fir the given name for the current record 0099 virtual QVariant value(const QString &field) const = 0; 0100 0101 //! Return the name of this source 0102 virtual QString sourceName() const; 0103 0104 //! @return the class name of this source 0105 virtual QString sourceClass() const; 0106 0107 //! Sets the sorting for the data 0108 //! Should be called before open() so that the data source can be edited accordingly 0109 //! Default impl does nothing 0110 virtual void setSorting(const QList<SortedField> &sorting); 0111 0112 //! Adds a condition to the data source 0113 virtual void addCondition(const QString &field, const QVariant &value, const QString& relation = QLatin1String("=")); 0114 0115 //! Return a list of data source names available for this data source 0116 //! Works after the source is opened 0117 virtual QStringList dataSourceNames() const = 0; 0118 0119 //! Return data source caption for specified @a dataSourceName 0120 //! It is possibly translated. As such it is suitable for use in GUIs. 0121 //! Default implementation just returns @a dataSourceName. 0122 virtual QString dataSourceCaption(const QString &dataSourceName) const; 0123 0124 //! Creates a new instance with data source. Default implementation returns @c nullptr. 0125 //! @a source is implementation-specific identifier. 0126 //! Owner of the returned pointer is the caller. 0127 Q_REQUIRED_RESULT virtual KReportDataSource* create(const QString &source) const; 0128 0129 private: 0130 Q_DISABLE_COPY(KReportDataSource) 0131 class Private; 0132 Private * const d; 0133 }; 0134 0135 #endif