File indexing completed on 2024-04-21 04:41:48

0001 /* This file is part of the KDE project
0002    Copyright (C) 2015 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 Library 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    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "KReportExampleDataSource.h"
0021 #include <QDebug>
0022 
0023 KReportExampleDataSource::KReportExampleDataSource()
0024 {
0025     QList<Data> temp {{ 0, "Adam Pigg", "Kexi", QObject::tr("United Kingdom"), "0123456789", 58.816, -3.1484, "1746287369", false },
0026                         {1, "Jaroslaw Staniek", "Kexi", QObject::tr("Poland"), "8472947462", 51.895182, 19.623270, "1234567890", true },
0027                         {2, "Boudewijn Rempt", "Krita", QObject::tr("Netherlands"), "8472947462", 48.858915, 2.347661, "1234567890", true }
0028     };
0029     m_testData = temp;
0030     m_fieldNames << "id" << "devname" << "project" << "country" << "mobile" << "lat" << "lon" << "code" << "projectlead";
0031     m_currentRecord = 0;
0032 }
0033 
0034 KReportExampleDataSource::~KReportExampleDataSource()
0035 {
0036 
0037 }
0038 
0039 QVariant KReportExampleDataSource::value(const QString& field) const
0040 {
0041     return value(fieldNumber(field));
0042 }
0043 
0044 QVariant KReportExampleDataSource::value(int f) const
0045 {
0046     switch(f) {
0047         case 0:
0048             return m_testData[m_currentRecord].id;
0049             break;
0050         case 1:
0051             return m_testData[m_currentRecord].devName;
0052             break;
0053 
0054         case 2:
0055             return m_testData[m_currentRecord].project;
0056             break;
0057 
0058         case 3:
0059             return m_testData[m_currentRecord].country;
0060             break;
0061 
0062         case 4:
0063             return m_testData[m_currentRecord].mobile;
0064             break;
0065 
0066         case 5:
0067             return m_testData[m_currentRecord].lat;
0068             break;
0069 
0070         case 6:
0071             return m_testData[m_currentRecord].lon;
0072             break;
0073 
0074         case 7:
0075             return m_testData[m_currentRecord].code;
0076             break;
0077 
0078         case 8:
0079             return m_testData[m_currentRecord].projectLead;
0080             break;
0081 
0082         default:
0083             return QVariant();
0084     }
0085 }
0086 
0087 QStringList KReportExampleDataSource::fieldNames() const
0088 {
0089     return m_fieldNames;
0090 }
0091 
0092 QStringList KReportExampleDataSource::fieldKeys() const
0093 {
0094     return fieldNames();
0095 }
0096 
0097 int KReportExampleDataSource::fieldNumber(const QString& field) const
0098 {
0099     return m_fieldNames.indexOf(field);
0100 }
0101 
0102 qint64 KReportExampleDataSource::recordCount() const
0103 {
0104     return m_testData.count();
0105 }
0106 
0107 qint64 KReportExampleDataSource::at() const
0108 {
0109     return m_currentRecord;
0110 }
0111 
0112 bool KReportExampleDataSource::moveLast()
0113 {
0114     m_currentRecord = recordCount() - 1;
0115     return true;
0116 }
0117 
0118 bool KReportExampleDataSource::moveFirst()
0119 {
0120     m_currentRecord = 0;
0121     return true;
0122 }
0123 
0124 bool KReportExampleDataSource::movePrevious()
0125 {
0126     if (m_currentRecord > 0) {
0127         m_currentRecord--;
0128         return true;
0129     }
0130     return false;
0131 }
0132 
0133 bool KReportExampleDataSource::moveNext()
0134 {
0135     if (m_currentRecord < recordCount() - 1) {
0136         m_currentRecord++;
0137         return true;
0138     }
0139     return false;
0140 }
0141 
0142 bool KReportExampleDataSource::close()
0143 {
0144     return true;
0145 }
0146 
0147 bool KReportExampleDataSource::open()
0148 {
0149     return true;
0150 }
0151 
0152 #ifdef KREPORT_SCRIPTING
0153 QStringList KReportExampleDataSource::scriptList() const
0154 {
0155     QStringList scripts;
0156 
0157     scripts << "example";
0158 
0159     return scripts;
0160 }
0161 
0162 QString KReportExampleDataSource::scriptCode(const QString &script) const
0163 {
0164     if (script != "example")
0165         return QString();
0166 
0167     QString scriptcode;
0168 
0169     scriptcode = ""
0170              "function detail(){\n"
0171              "  var count = 0;"
0172              "  this.OnRender = function() {\n"
0173              "    count++;\n"
0174              "    debug.print(\"printing this from the javascript engine\");\n"
0175              "    if (count % 2 == 0) {\n"
0176              "      example_report.section_detail.setBackgroundColor(\"#ffffff\");\n"
0177              "    } else {\n"
0178              "      example_report.section_detail.setBackgroundColor(\"#dddddd\");\n"
0179              "    }\n"
0180              "    example_report.section_detail.objectByName(\"label1\").setCaption(\"Record: \" + count);\n"
0181              "  }\n"
0182              "}\n"
0183              "\n"
0184              "function report(){\n"
0185              "  this.OnOpen = function() {\n"
0186              "    debug.print(\"report on-open event\");\n"
0187              "  }\n"
0188              "}\n"
0189              "example_report.section_detail.initialize(new detail());\n"
0190              "example_report.initialize(new report());\n";
0191 
0192     return scriptcode;
0193 }
0194 #endif
0195 
0196 QStringList KReportExampleDataSource::dataSourceNames() const
0197 {
0198     return QStringList();
0199 }