1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
/* This file is part of the KDE project
Copyright (C) 2015 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 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 "KReportExampleDataSource.h"
#include <QDebug>
KReportExampleDataSource::KReportExampleDataSource()
{
QList<Data> temp {{ 0, "Adam Pigg", "Kexi", QObject::tr("United Kingdom"), "0123456789", 58.816, -3.1484, "1746287369", false },
{1, "Jaroslaw Staniek", "Kexi", QObject::tr("Poland"), "8472947462", 51.895182, 19.623270, "1234567890", true },
{2, "Boudewijn Rempt", "Krita", QObject::tr("Netherlands"), "8472947462", 48.858915, 2.347661, "1234567890", true }
};
m_testData = temp;
m_fieldNames << "id" << "devname" << "project" << "country" << "mobile" << "lat" << "lon" << "code" << "projectlead";
m_currentRecord = 0;
}
KReportExampleDataSource::~KReportExampleDataSource()
{
}
QVariant KReportExampleDataSource::value(const QString& field) const
{
return value(fieldNumber(field));
}
QVariant KReportExampleDataSource::value(int f) const
{
switch(f) {
case 0:
return m_testData[m_currentRecord].id;
break;
case 1:
return m_testData[m_currentRecord].devName;
break;
case 2:
return m_testData[m_currentRecord].project;
break;
case 3:
return m_testData[m_currentRecord].country;
break;
case 4:
return m_testData[m_currentRecord].mobile;
break;
case 5:
return m_testData[m_currentRecord].lat;
break;
case 6:
return m_testData[m_currentRecord].lon;
break;
case 7:
return m_testData[m_currentRecord].code;
break;
case 8:
return m_testData[m_currentRecord].projectLead;
break;
default:
return QVariant();
}
}
QStringList KReportExampleDataSource::fieldNames() const
{
return m_fieldNames;
}
QStringList KReportExampleDataSource::fieldKeys() const
{
return fieldNames();
}
int KReportExampleDataSource::fieldNumber(const QString& field) const
{
return m_fieldNames.indexOf(field);
}
qint64 KReportExampleDataSource::recordCount() const
{
return m_testData.count();
}
qint64 KReportExampleDataSource::at() const
{
return m_currentRecord;
}
bool KReportExampleDataSource::moveLast()
{
m_currentRecord = recordCount() - 1;
return true;
}
bool KReportExampleDataSource::moveFirst()
{
m_currentRecord = 0;
return true;
}
bool KReportExampleDataSource::movePrevious()
{
if (m_currentRecord > 0) {
m_currentRecord--;
return true;
}
return false;
}
bool KReportExampleDataSource::moveNext()
{
if (m_currentRecord < recordCount() - 1) {
m_currentRecord++;
return true;
}
return false;
}
bool KReportExampleDataSource::close()
{
return true;
}
bool KReportExampleDataSource::open()
{
return true;
}
#ifdef KREPORT_SCRIPTING
QStringList KReportExampleDataSource::scriptList() const
{
QStringList scripts;
scripts << "example";
return scripts;
}
QString KReportExampleDataSource::scriptCode(const QString &script) const
{
if (script != "example")
return QString();
QString scriptcode;
scriptcode = ""
"function detail(){\n"
" var count = 0;"
" this.OnRender = function() {\n"
" count++;\n"
" debug.print(\"printing this from the javascript engine\");\n"
" if (count % 2 == 0) {\n"
" example_report.section_detail.setBackgroundColor(\"#ffffff\");\n"
" } else {\n"
" example_report.section_detail.setBackgroundColor(\"#dddddd\");\n"
" }\n"
" example_report.section_detail.objectByName(\"label1\").setCaption(\"Record: \" + count);\n"
" }\n"
"}\n"
"\n"
"function report(){\n"
" this.OnOpen = function() {\n"
" debug.print(\"report on-open event\");\n"
" }\n"
"}\n"
"example_report.section_detail.initialize(new detail());\n"
"example_report.initialize(new report());\n";
return scriptcode;
}
#endif
QStringList KReportExampleDataSource::dataSourceNames() const
{
return QStringList();
}
|