Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/reports/kexireportpart.cpp
Show All 17 Lines | |||||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | 20 | | |||
21 | #include "kexireportpart.h" | 21 | #include "kexireportpart.h" | ||
22 | 22 | | |||
23 | #include <QTabWidget> | 23 | #include <QTabWidget> | ||
24 | #include <QDebug> | 24 | #include <QDebug> | ||
25 | 25 | | |||
26 | #include <KDbConnection> | ||||
27 | | ||||
26 | #include <KLocalizedString> | 28 | #include <KLocalizedString> | ||
27 | 29 | | |||
28 | #include <KexiIcon.h> | 30 | #include <KexiIcon.h> | ||
29 | #include <core/KexiWindow.h> | 31 | #include <core/KexiWindow.h> | ||
30 | #include "kexireportview.h" | 32 | #include "kexireportview.h" | ||
31 | #include "kexireportdesignview.h" | 33 | #include "kexireportdesignview.h" | ||
32 | #include <core/KexiMainWindowIface.h> | 34 | #include <core/KexiMainWindowIface.h> | ||
33 | #include "kexisourceselector.h" | 35 | #include "kexisourceselector.h" | ||
Show All 9 Lines | 41 | public: | |||
43 | } | 45 | } | ||
44 | ~Private() { | 46 | ~Private() { | ||
45 | } | 47 | } | ||
46 | KexiSourceSelector *sourceSelector; | 48 | KexiSourceSelector *sourceSelector; | ||
47 | QActionGroup toolboxActionGroup; | 49 | QActionGroup toolboxActionGroup; | ||
48 | QMap<QString, QAction*> toolboxActionsByName; | 50 | QMap<QString, QAction*> toolboxActionsByName; | ||
49 | }; | 51 | }; | ||
50 | 52 | | |||
53 | static bool isInterpreterSupported(const QString &interpreterName) | ||||
54 | { | ||||
55 | return 0 == interpreterName.compare(QLatin1String("javascript"), Qt::CaseInsensitive) | ||||
56 | || 0 == interpreterName.compare(QLatin1String("qtscript"), Qt::CaseInsensitive); | ||||
57 | } | ||||
58 | | ||||
51 | KexiReportPart::KexiReportPart(QObject *parent, const QVariantList &l) | 59 | KexiReportPart::KexiReportPart(QObject *parent, const QVariantList &l) | ||
52 | : KexiPart::Part(parent, | 60 | : KexiPart::Part(parent, | ||
53 | xi18nc("Translate this word using only lowercase alphanumeric characters (a..z, 0..9). " | 61 | xi18nc("Translate this word using only lowercase alphanumeric characters (a..z, 0..9). " | ||
54 | "Use '_' character instead of spaces. First character should be a..z character. " | 62 | "Use '_' character instead of spaces. First character should be a..z character. " | ||
55 | "If you cannot use latin characters in your language, use english word.", | 63 | "If you cannot use latin characters in your language, use english word.", | ||
56 | "report"), | 64 | "report"), | ||
57 | xi18nc("tooltip", "Create new report"), | 65 | xi18nc("tooltip", "Create new report"), | ||
58 | xi18nc("what's this", "Creates new report."), | 66 | xi18nc("what's this", "Creates new report."), | ||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Line(s) | 203 | { | |||
196 | Q_UNUSED(entity); | 204 | Q_UNUSED(entity); | ||
197 | // uncheck toolbox action after it is used | 205 | // uncheck toolbox action after it is used | ||
198 | QAction * a = d->toolboxActionGroup.checkedAction(); | 206 | QAction * a = d->toolboxActionGroup.checkedAction(); | ||
199 | if (a) { | 207 | if (a) { | ||
200 | a->setChecked(false); | 208 | a->setChecked(false); | ||
201 | } | 209 | } | ||
202 | } | 210 | } | ||
203 | 211 | | |||
212 | QStringList KexiReportPart::scriptList() const | ||||
213 | { | ||||
214 | QStringList scripts; | ||||
215 | | ||||
216 | KexiMainWindowIface *win = KexiMainWindowIface::global(); | ||||
217 | | ||||
218 | if (win->project() && win->project()->dbConnection()) { | ||||
staniek: `if (foo) {` | |||||
staniek: if (win | |||||
219 | QList<int> scriptids = win->project()->dbConnection()->objectIds(KexiPart::ScriptObjectType); | ||||
220 | QStringList scriptnames = win->project()->dbConnection()->objectNames(KexiPart::ScriptObjectType); | ||||
221 | | ||||
222 | qDebug() << scriptids << scriptnames; | ||||
223 | | ||||
224 | int i = 0; | ||||
225 | foreach(int id, scriptids) { | ||||
Why do we need it? KReportDesigner::slotPageButton_Pressed() prepends empty item too... Maybe I missed something. staniek: Why do we need it? KReportDesigner::slotPageButton_Pressed() prepends empty item too...
Maybe… | |||||
226 | qDebug() << "ID:" << id; | ||||
227 | tristate res; | ||||
228 | QString script; | ||||
229 | res = win->project()->dbConnection()->loadDataBlock(id, &script, QString()); | ||||
230 | if (res == true) { | ||||
231 | QDomDocument domdoc; | ||||
232 | bool parsed = domdoc.setContent(script, false); | ||||
233 | | ||||
234 | QDomElement scriptelem = domdoc.namedItem("script").toElement(); | ||||
235 | if (parsed && !scriptelem.isNull()) { | ||||
236 | if (scriptelem.attribute("scripttype") == "object" | ||||
237 | && isInterpreterSupported(scriptelem.attribute("language"))) | ||||
238 | { | ||||
239 | scripts << scriptnames[i]; | ||||
240 | } | ||||
241 | } else { | ||||
242 | qWarning() << "Unable to parse script"; | ||||
staniek: -> qWarning | |||||
243 | } | ||||
244 | } else { | ||||
245 | qWarning() << "Unable to loadDataBlock"; | ||||
staniek: -> qWarning | |||||
246 | } | ||||
247 | ++i; | ||||
248 | } | ||||
249 | | ||||
250 | qDebug() << scripts; | ||||
251 | } | ||||
252 | return scripts; | ||||
253 | } | ||||
254 | | ||||
255 | QString KexiReportPart::scriptCode(const QString& scriptname) const | ||||
256 | { | ||||
257 | QString scripts; | ||||
258 | | ||||
259 | KexiMainWindowIface *win = KexiMainWindowIface::global(); | ||||
260 | | ||||
261 | if (win->project() && win->project()->dbConnection()) { | ||||
262 | QList<int> scriptids = win->project()->dbConnection()->objectIds(KexiPart::ScriptObjectType); | ||||
263 | QStringList scriptnames = win->project()->dbConnection()->objectNames(KexiPart::ScriptObjectType); | ||||
264 | | ||||
265 | int i = 0; | ||||
266 | foreach(int id, scriptids) { | ||||
267 | qDebug() << "ID:" << id; | ||||
268 | tristate res; | ||||
269 | QString script; | ||||
270 | res = win->project()->dbConnection()->loadDataBlock(id, &script, QString()); | ||||
271 | if (res == true) { | ||||
272 | QDomDocument domdoc; | ||||
273 | bool parsed = domdoc.setContent(script, false); | ||||
274 | | ||||
275 | if (! parsed) { | ||||
276 | qWarning() << "XML parsing error"; | ||||
staniek: -> qWarning | |||||
277 | return QString(); | ||||
278 | } | ||||
279 | | ||||
280 | QDomElement scriptelem = domdoc.namedItem("script").toElement(); | ||||
281 | if (scriptelem.isNull()) { | ||||
282 | qWarning() << "script domelement is null"; | ||||
staniek: -> qWarning | |||||
283 | return QString(); | ||||
284 | } | ||||
285 | | ||||
286 | QString interpretername = scriptelem.attribute("language"); | ||||
287 | qDebug() << scriptelem.attribute("scripttype"); | ||||
288 | qDebug() << scriptname << scriptnames[i]; | ||||
289 | | ||||
290 | if ((isInterpreterSupported(interpretername) && scriptelem.attribute("scripttype") == "module") || scriptname == scriptnames[i]) | ||||
291 | { | ||||
292 | scripts += '\n' + scriptelem.text().toUtf8(); | ||||
293 | } | ||||
294 | ++i; | ||||
295 | } else { | ||||
296 | qWarning() << "Unable to loadDataBlock"; | ||||
staniek: -> qWarning | |||||
297 | } | ||||
298 | } | ||||
299 | } | ||||
300 | return scripts; | ||||
301 | } |
if (foo) {