Changeset View
Changeset View
Standalone View
Standalone View
examples/KReportExampleDataSource.cpp
- This file was moved from examples/KReportExampleData.cpp.
Show All 11 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
12 | Library General Public License for more details. | 12 | Library General Public License for more details. | ||
13 | 13 | | |||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "KReportExampleData.h" | 20 | #include "KReportExampleDataSource.h" | ||
21 | #include <QDebug> | 21 | #include <QDebug> | ||
22 | 22 | | |||
23 | KReportExampleData::KReportExampleData() | 23 | KReportExampleDataSource::KReportExampleDataSource() | ||
24 | { | 24 | { | ||
25 | QList<Data> temp {{ 0, "Adam Pigg", "Kexi", QObject::tr("United Kingdom"), "0123456789", 58.816, -3.1484, "1746287369", false }, | 25 | QList<Data> temp {{ 0, "Adam Pigg", "Kexi", QObject::tr("United Kingdom"), "0123456789", 58.816, -3.1484, "1746287369", false }, | ||
26 | {1, "Jaroslaw Staniek", "Kexi", QObject::tr("Poland"), "8472947462", 51.895182, 19.623270, "1234567890", true }, | 26 | {1, "Jaroslaw Staniek", "Kexi", QObject::tr("Poland"), "8472947462", 51.895182, 19.623270, "1234567890", true }, | ||
27 | {2, "Boudewijn Rempt", "Krita", QObject::tr("Netherlands"), "8472947462", 48.858915, 2.347661, "1234567890", true }, | 27 | {2, "Boudewijn Rempt", "Krita", QObject::tr("Netherlands"), "8472947462", 48.858915, 2.347661, "1234567890", true }, | ||
28 | }; | 28 | }; | ||
29 | m_testData = temp; | 29 | m_testData = temp; | ||
30 | m_fieldNames << "id" << "devname" << "project" << "country" << "mobile" << "lat" << "lon" << "code" << "projectlead"; | 30 | m_fieldNames << "id" << "devname" << "project" << "country" << "mobile" << "lat" << "lon" << "code" << "projectlead"; | ||
31 | m_currentRecord = 0; | 31 | m_currentRecord = 0; | ||
32 | } | 32 | } | ||
33 | 33 | | |||
34 | KReportExampleData::~KReportExampleData() | 34 | KReportExampleDataSource::~KReportExampleDataSource() | ||
35 | { | 35 | { | ||
36 | 36 | | |||
37 | } | 37 | } | ||
38 | 38 | | |||
39 | QVariant KReportExampleData::value(const QString& field) const | 39 | QVariant KReportExampleDataSource::value(const QString& field) const | ||
40 | { | 40 | { | ||
41 | return value(fieldNumber(field)); | 41 | return value(fieldNumber(field)); | ||
42 | } | 42 | } | ||
43 | 43 | | |||
44 | QVariant KReportExampleData::value(unsigned int f) const | 44 | QVariant KReportExampleDataSource::value(int f) const | ||
45 | { | 45 | { | ||
46 | switch(f) { | 46 | switch(f) { | ||
47 | case 0: | 47 | case 0: | ||
48 | return m_testData[m_currentRecord].id; | 48 | return m_testData[m_currentRecord].id; | ||
49 | break; | 49 | break; | ||
50 | case 1: | 50 | case 1: | ||
51 | return m_testData[m_currentRecord].devName; | 51 | return m_testData[m_currentRecord].devName; | ||
52 | break; | 52 | break; | ||
Show All 26 Lines | 78 | case 8: | |||
79 | return m_testData[m_currentRecord].projectLead; | 79 | return m_testData[m_currentRecord].projectLead; | ||
80 | break; | 80 | break; | ||
81 | 81 | | |||
82 | default: | 82 | default: | ||
83 | return QVariant(); | 83 | return QVariant(); | ||
84 | } | 84 | } | ||
85 | } | 85 | } | ||
86 | 86 | | |||
87 | QStringList KReportExampleData::fieldNames() const | 87 | QStringList KReportExampleDataSource::fieldNames() const | ||
88 | { | 88 | { | ||
89 | return m_fieldNames; | 89 | return m_fieldNames; | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | QStringList KReportExampleData::fieldKeys() const | 92 | QStringList KReportExampleDataSource::fieldKeys() const | ||
93 | { | 93 | { | ||
94 | return fieldNames(); | 94 | return fieldNames(); | ||
95 | } | 95 | } | ||
96 | 96 | | |||
97 | int KReportExampleData::fieldNumber(const QString& field) const | 97 | int KReportExampleDataSource::fieldNumber(const QString& field) const | ||
98 | { | 98 | { | ||
99 | return m_fieldNames.indexOf(field); | 99 | return m_fieldNames.indexOf(field); | ||
100 | } | 100 | } | ||
101 | 101 | | |||
102 | qint64 KReportExampleData::recordCount() const | 102 | qint64 KReportExampleDataSource::recordCount() const | ||
103 | { | 103 | { | ||
104 | return m_testData.count(); | 104 | return m_testData.count(); | ||
105 | } | 105 | } | ||
106 | 106 | | |||
107 | qint64 KReportExampleData::at() const | 107 | qint64 KReportExampleDataSource::at() const | ||
108 | { | 108 | { | ||
109 | return m_currentRecord; | 109 | return m_currentRecord; | ||
110 | } | 110 | } | ||
111 | 111 | | |||
112 | bool KReportExampleData::moveLast() | 112 | bool KReportExampleDataSource::moveLast() | ||
113 | { | 113 | { | ||
114 | m_currentRecord = recordCount() - 1; | 114 | m_currentRecord = recordCount() - 1; | ||
115 | return true; | 115 | return true; | ||
116 | } | 116 | } | ||
117 | 117 | | |||
118 | bool KReportExampleData::moveFirst() | 118 | bool KReportExampleDataSource::moveFirst() | ||
119 | { | 119 | { | ||
120 | m_currentRecord = 0; | 120 | m_currentRecord = 0; | ||
121 | return true; | 121 | return true; | ||
122 | } | 122 | } | ||
123 | 123 | | |||
124 | bool KReportExampleData::movePrevious() | 124 | bool KReportExampleDataSource::movePrevious() | ||
125 | { | 125 | { | ||
126 | if (m_currentRecord > 0) { | 126 | if (m_currentRecord > 0) { | ||
127 | m_currentRecord--; | 127 | m_currentRecord--; | ||
128 | return true; | 128 | return true; | ||
129 | } | 129 | } | ||
130 | return false; | 130 | return false; | ||
131 | } | 131 | } | ||
132 | 132 | | |||
133 | bool KReportExampleData::moveNext() | 133 | bool KReportExampleDataSource::moveNext() | ||
134 | { | 134 | { | ||
135 | if (m_currentRecord < recordCount() - 1) { | 135 | if (m_currentRecord < recordCount() - 1) { | ||
136 | m_currentRecord++; | 136 | m_currentRecord++; | ||
137 | return true; | 137 | return true; | ||
138 | } | 138 | } | ||
139 | return false; | 139 | return false; | ||
140 | } | 140 | } | ||
141 | 141 | | |||
142 | bool KReportExampleData::close() | 142 | bool KReportExampleDataSource::close() | ||
143 | { | 143 | { | ||
144 | return true; | 144 | return true; | ||
145 | } | 145 | } | ||
146 | 146 | | |||
147 | bool KReportExampleData::open() | 147 | bool KReportExampleDataSource::open() | ||
148 | { | 148 | { | ||
149 | return true; | 149 | return true; | ||
150 | } | 150 | } | ||
151 | 151 | | |||
152 | QStringList KReportExampleData::scriptList() const | 152 | QStringList KReportExampleDataSource::scriptList() const | ||
153 | { | 153 | { | ||
154 | QStringList scripts; | 154 | QStringList scripts; | ||
155 | 155 | | |||
156 | scripts << "example"; | 156 | scripts << "example"; | ||
157 | 157 | | |||
158 | return scripts; | 158 | return scripts; | ||
159 | } | 159 | } | ||
160 | 160 | | |||
161 | QString KReportExampleData::scriptCode(const QString &script) const | 161 | QString KReportExampleDataSource::scriptCode(const QString &script) const | ||
162 | { | 162 | { | ||
163 | if (script != "example") | 163 | if (script != "example") | ||
164 | return QString(); | 164 | return QString(); | ||
165 | 165 | | |||
166 | QString scriptcode; | 166 | QString scriptcode; | ||
167 | 167 | | |||
168 | scriptcode = "" | 168 | scriptcode = "" | ||
169 | "function detail(){\n" | 169 | "function detail(){\n" | ||
Show All 15 Lines | |||||
185 | " debug.print(\"report on-open event\");\n" | 185 | " debug.print(\"report on-open event\");\n" | ||
186 | " }\n" | 186 | " }\n" | ||
187 | "}\n" | 187 | "}\n" | ||
188 | "example_report.section_detail.initialize(new detail());\n" | 188 | "example_report.section_detail.initialize(new detail());\n" | ||
189 | "example_report.initialize(new report());\n"; | 189 | "example_report.initialize(new report());\n"; | ||
190 | 190 | | |||
191 | return scriptcode; | 191 | return scriptcode; | ||
192 | } | 192 | } | ||
193 | | ||||
194 | QStringList KReportExampleDataSource::dataSourceNames() const | ||||
195 | { | ||||
196 | return QStringList(); | ||||
197 | } |