Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/reports/kexireportdesignview.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Kexi Report Plugin | 2 | * Kexi Report Plugin | ||
3 | * Copyright (C) 2007-2009 by Adam Pigg <adam@piggz.co.uk> | 3 | * Copyright (C) 2007-2009 by Adam Pigg <adam@piggz.co.uk> | ||
4 | * Copyright (C) 2011 Jarosław Staniek <staniek@kde.org> | 4 | * Copyright (C) 2011-2017 Jarosław Staniek <staniek@kde.org> | ||
5 | * | 5 | * | ||
6 | * This library is free software; you can redistribute it and/or | 6 | * This library is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | 7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | 8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | 9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | 10 | * | ||
11 | * This library is distributed in the hope that it will be useful, | 11 | * This library is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | 14 | * Lesser General Public License for more details. | ||
15 | * | 15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | 16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "kexireportdesignview.h" | 20 | #include "kexireportdesignview.h" | ||
21 | #include <core/KexiMainWindowIface.h> | 21 | #include <core/KexiMainWindowIface.h> | ||
22 | #include <core/KexiWindow.h> | 22 | #include <core/KexiWindow.h> | ||
23 | #include "kexisourceselector.h" | 23 | #include "kexisourceselector.h" | ||
24 | #include <KexiIcon.h> | 24 | #include <KexiIcon.h> | ||
25 | #include <kexiutils/utils.h> | ||||
25 | 26 | | |||
26 | #include <KDbConnection> | 27 | #include <KDbConnection> | ||
27 | 28 | | |||
28 | #include <QShortcut> | 29 | #include <QShortcut> | ||
29 | #include <QDebug> | 30 | #include <QDebug> | ||
30 | #include <QScrollArea> | 31 | #include <QScrollArea> | ||
31 | #include <QLayout> | 32 | #include <QLayout> | ||
32 | 33 | | |||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | |||||
108 | } | 109 | } | ||
109 | 110 | | |||
110 | tristate KexiReportDesignView::storeData(bool dontAsk) | 111 | tristate KexiReportDesignView::storeData(bool dontAsk) | ||
111 | { | 112 | { | ||
112 | Q_UNUSED(dontAsk); | 113 | Q_UNUSED(dontAsk); | ||
113 | 114 | | |||
114 | QDomDocument doc("kexireport"); | 115 | QDomDocument doc("kexireport"); | ||
115 | QDomElement root = doc.createElement("kexireport"); | 116 | QDomElement root = doc.createElement("kexireport"); | ||
116 | QDomElement conndata = m_sourceSelector->connectionData(); | 117 | QDomElement conndata = connectionData(); | ||
117 | 118 | | |||
118 | if (conndata.isNull()) | 119 | if (conndata.isNull()) | ||
119 | qDebug() << "Null conn data!"; | 120 | qDebug() << "Null conn data!"; | ||
120 | 121 | | |||
121 | root.appendChild(m_reportDesigner->document()); | 122 | root.appendChild(m_reportDesigner->document()); | ||
122 | root.appendChild(conndata); | 123 | root.appendChild(conndata); | ||
123 | doc.appendChild(root); | 124 | doc.appendChild(root); | ||
124 | 125 | | |||
Show All 32 Lines | 153 | { | |||
157 | } else { | 158 | } else { | ||
158 | if (m_reportDesigner) { | 159 | if (m_reportDesigner) { | ||
159 | m_scrollArea->takeWidget(); | 160 | m_scrollArea->takeWidget(); | ||
160 | delete m_reportDesigner; | 161 | delete m_reportDesigner; | ||
161 | m_reportDesigner = 0; | 162 | m_reportDesigner = 0; | ||
162 | } | 163 | } | ||
163 | 164 | | |||
164 | m_reportDesigner = new KReportDesigner(this, tempData()->reportDefinition); | 165 | m_reportDesigner = new KReportDesigner(this, tempData()->reportDefinition); | ||
165 | m_sourceSelector->setConnectionData(tempData()->connectionDefinition); | 166 | setConnectionData(tempData()->connectionDefinition); | ||
166 | m_reportDesigner->setScriptSource(qobject_cast<KexiReportPart*>(part())); | 167 | m_reportDesigner->setScriptSource(qobject_cast<KexiReportPart*>(part())); | ||
167 | } | 168 | } | ||
168 | connect(m_reportDesigner, SIGNAL(itemInserted(QString)), this, SIGNAL(itemInserted(QString))); | 169 | connect(m_reportDesigner, SIGNAL(itemInserted(QString)), this, SIGNAL(itemInserted(QString))); | ||
169 | 170 | | |||
170 | m_scrollArea->setWidget(m_reportDesigner); | 171 | m_scrollArea->setWidget(m_reportDesigner); | ||
171 | 172 | | |||
172 | connect(m_reportDesigner, SIGNAL(propertySetChanged()), this, SLOT(slotDesignerPropertySetChanged())); | 173 | connect(m_reportDesigner, SIGNAL(propertySetChanged()), this, SLOT(slotDesignerPropertySetChanged())); | ||
173 | connect(m_reportDesigner, SIGNAL(dirty()), this, SLOT(setDirty())); | 174 | connect(m_reportDesigner, SIGNAL(dirty()), this, SLOT(setDirty())); | ||
Show All 25 Lines | |||||
199 | 200 | | |||
200 | KexiReportPartTempData* KexiReportDesignView::tempData() const | 201 | KexiReportPartTempData* KexiReportDesignView::tempData() const | ||
201 | { | 202 | { | ||
202 | return static_cast<KexiReportPartTempData*>(window()->data()); | 203 | return static_cast<KexiReportPartTempData*>(window()->data()); | ||
203 | } | 204 | } | ||
204 | 205 | | |||
205 | void KexiReportDesignView::slotDataSourceChanged() | 206 | void KexiReportDesignView::slotDataSourceChanged() | ||
206 | { | 207 | { | ||
207 | m_reportDesigner->setDataSource(m_sourceSelector->createDataSource()); | 208 | if (m_sourceSelector->isSelectionValid()) { | ||
208 | tempData()->connectionDefinition = m_sourceSelector->connectionData(); | 209 | m_reportDesigner->setDataSource(new KexiDBReportDataSource( | ||
210 | m_sourceSelector->selectedName(), m_sourceSelector->selectedPluginId(), tempData())); | ||||
211 | tempData()->connectionDefinition = connectionData(); | ||||
212 | } else { | ||||
213 | m_reportDesigner->setDataSource(nullptr); | ||||
214 | tempData()->connectionDefinition = QDomElement(); | ||||
215 | } | ||||
209 | setDirty(true); | 216 | setDirty(true); | ||
210 | } | 217 | } | ||
211 | 218 | | |||
212 | void KexiReportDesignView::triggerAction(const QString &action) | 219 | void KexiReportDesignView::triggerAction(const QString &action) | ||
213 | { | 220 | { | ||
214 | m_reportDesigner->slotItem(action); | 221 | m_reportDesigner->slotItem(action); | ||
215 | } | 222 | } | ||
223 | | ||||
224 | QDomElement KexiReportDesignView::connectionData() const | ||||
225 | { | ||||
226 | QDomDocument dd; | ||||
227 | QDomElement conndata = dd.createElement("connection"); | ||||
228 | conndata.setAttribute("type", "internal"); // for backward compatibility, currently always | ||||
229 | // internal, we used to have "external" in old Kexi | ||||
230 | conndata.setAttribute("source", m_sourceSelector->selectedName()); | ||||
231 | conndata.setAttribute("class", m_sourceSelector->selectedPluginId()); | ||||
232 | return conndata; | ||||
233 | } | ||||
234 | | ||||
235 | void KexiReportDesignView::setConnectionData(const QDomElement &c) | ||||
236 | { | ||||
237 | qDebug() << c; | ||||
238 | if (c.attribute("type") == "internal") { | ||||
239 | QString sourceClass(c.attribute("class")); | ||||
240 | if (sourceClass != "org.kexi-project.table" && sourceClass != "org.kexi-project.query") { | ||||
241 | sourceClass.clear(); // KexiDataSourceComboBox will try to find table, then query | ||||
242 | } | ||||
243 | m_sourceSelector->setDataSource(sourceClass, c.attribute("source")); | ||||
244 | slotDataSourceChanged(); | ||||
245 | } | ||||
246 | } |