20#include "KReportDesigner.h"
21#include "KReportDesign_p.h"
22#include "KReportDesignerItemLine.h"
23#include "KReportDesignerSection.h"
24#include "KReportDesignerSectionDetail.h"
25#include "KReportDesignerSectionDetailGroup.h"
26#include "KReportDesignerSectionScene.h"
27#include "KReportDesignerSectionView.h"
28#include "KReportPageSize.h"
29#include "KReportPluginInterface.h"
30#include "KReportPluginManager.h"
31#include "KReportPluginMetaData.h"
32#include "KReportPropertiesButton.h"
33#include "KReportRuler_p.h"
34#include "KReportSection.h"
35#include "KReportSectionEditor.h"
36#include "KReportUtils.h"
37#include "KReportUtils_p.h"
38#include "KReportZoomHandler_p.h"
39#include "kreport_debug.h"
40#ifdef KREPORT_SCRIPTING
41#include "KReportScriptSource.h"
44#include <KPropertyListData>
46#include <KStandardShortcut>
47#include <KStandardGuiItem>
49#include <QDomDocument>
52#include <QGraphicsSceneMouseEvent>
61const char ns[] =
"http://kexi-project.org/report/2.0";
74class ReportWriterSectionData
77 ReportWriterSectionData() {
78 selected_x_offset = 0;
79 selected_y_offset = 0;
80 mouseAction = MouseAction::None;
82 virtual ~ReportWriterSectionData() {
85 enum class MouseAction {
101 int selected_x_offset;
102 int selected_y_offset;
104 MouseAction mouseAction;
105 QString itemToInsert;
107 QList<KReportDesignerItemBase*> copy_list;
108 QList<KReportDesignerItemBase*> cut_list;
115 explicit Private(KReportDesigner *designer);
122 void init(
const QDomElement *xml);
124 void updateCurrentUnit() {
125 QString u = unit->value().toString();
128 currentUnit = newUnit;
130 currentUnit = DEFAULT_UNIT;
133 if (u == QLatin1String(
"dm")) {
134 gridDivisions->setOption(
"max", 100);
136 gridDivisions->setOption(
"max", 10);
137 if (gridDivisions->value().toInt() > 10) {
138 gridDivisions->setValue(10, KProperty::ValueOption::IgnoreOld);
143#ifdef KREPORT_SCRIPTING
144 void updateScripts();
147 KReportDesigner *
const q;
150 KReportRuler *hruler;
151 KReportZoomHandler zoomHandler;
152 QVBoxLayout *vboxlayout;
153 KReportPropertiesButton *pageButton;
155 QGraphicsScene *activeScene =
nullptr;
157 ReportWriterSectionData sectionData;
159 KReportDesignerSection *reportHeader =
nullptr;
160 KReportDesignerSection *pageHeaderFirst =
nullptr;
161 KReportDesignerSection *pageHeaderOdd =
nullptr;
162 KReportDesignerSection *pageHeaderEven =
nullptr;
163 KReportDesignerSection *pageHeaderLast =
nullptr;
164 KReportDesignerSection *pageHeaderAny =
nullptr;
166 KReportDesignerSection *pageFooterFirst =
nullptr;
167 KReportDesignerSection *pageFooterOdd =
nullptr;
168 KReportDesignerSection *pageFooterEven =
nullptr;
169 KReportDesignerSection *pageFooterLast =
nullptr;
170 KReportDesignerSection *pageFooterAny =
nullptr;
171 KReportDesignerSection *reportFooter =
nullptr;
172 KReportDesignerSectionDetail *detail =
nullptr;
176 KPropertySet *itemSet;
179 KProperty *orientation;
181 KProperty *customPageSize;
182 KProperty *leftMargin;
183 KProperty *rightMargin;
184 KProperty *topMargin;
185 KProperty *bottomMargin;
187 KProperty *gridDivisions;
189 KProperty *labelType;
190#ifdef KREPORT_SCRIPTING
194 KReportUnit currentUnit;
197 QAction *editCutAction;
198 QAction *editCopyAction;
199 QAction *editPasteAction;
200 QAction *editDeleteAction;
201 QAction *sectionEdit;
202 QAction *parameterEdit;
203 QAction *itemRaiseAction;
204 QAction *itemLowerAction;
211 bool modified =
false;
213 QString originalInterpreter;
214 QString originalScript;
216 KReportDataSource *dataSource =
nullptr;
217#ifdef KREPORT_SCRIPTING
218 KReportScriptSource *scriptSource =
nullptr;
222 void loadXml(
const QDomElement &data);
226 : q(designer), currentUnit(DEFAULT_UNIT_TYPE)
231void KReportDesigner::Private::init(
const QDomElement *xml)
233 KReportPluginManager::self();
235 q->createProperties();
238 grid =
new QGridLayout(q);
241 grid->setColumnStretch(1, 1);
242 grid->setRowStretch(1, 1);
245 vboxlayout =
new QVBoxLayout();
246 vboxlayout->setSpacing(0);
247 vboxlayout->setMargin(0);
252 hruler->setUnit(DEFAULT_UNIT);
254 pageButton =
new KReportPropertiesButton;
256 grid->addWidget(pageButton, 0, 0);
257 grid->addWidget(hruler, 0, 1);
258 grid->addLayout(vboxlayout, 1, 0, 1, 2);
260 pageButton->setMaximumSize(QSize(19, 22));
261 pageButton->setMinimumSize(QSize(19, 22));
264 detail =
new KReportDesignerSectionDetail(q);
265 vboxlayout->insertWidget(0, detail);
269 q, &KReportDesigner::slotPageButton_Pressed);
270 emit q->pagePropertyChanged(set);
277 set.clearModifiedFlags();
281void KReportDesigner::Private::loadXml(
const QDomElement &data)
283 if (data.
tagName() != QLatin1String(
"report:content")) {
285 kreportWarning() <<
"root element was not <report:content>";
292 for (
int i = 0; i < nlist.
count(); ++i) {
298 if (n == QLatin1String(
"report:title")) {
300#ifdef KREPORT_SCRIPTING
301 }
else if (n == QLatin1String(
"report:script")) {
302 originalInterpreter = it.
toElement().
attribute(QLatin1String(
"report:script-interpreter"), QLatin1String(
"javascript"));
303 if (originalInterpreter.isEmpty()) {
304 originalInterpreter = QLatin1String(
"javascript");
307 script->setValue(originalScript);
309 if (originalInterpreter != QLatin1String(
"javascript") && originalInterpreter != QLatin1String(
"qtscript")) {
310 QString msg =
tr(
"This report contains scripts of type \"%1\". "
311 "Only scripts written in JavaScript language are "
312 "supported. To prevent losing the scripts, their type "
313 "and content will not be changed unless you change these scripts."
314 ).
arg(originalInterpreter);
318 }
else if (n == QLatin1String(
"report:grid")) {
322 unit->setValue(it.
toElement().
attribute(QLatin1String(
"report:page-unit"), DEFAULT_UNIT_STRING));
327 else if (n == QLatin1String(
"report:page-style")) {
330 if (pagetype == QLatin1String(
"predefined")) {
332 }
else if (pagetype == QLatin1String(
"custom")) {
333 pageSize->setValue(QLatin1String(
"Custom"));
336 }
else if (pagetype == QLatin1String(
"label")) {
340 rightMargin->setValue(currentUnit.convertFromPoint(
342 QLatin1String(
"fo:margin-right"), DEFAULT_PAGE_MARGIN_STRING))));
343 leftMargin->setValue(currentUnit.convertFromPoint(
345 QLatin1String(
"fo:margin-left"), DEFAULT_PAGE_MARGIN_STRING))));
346 topMargin->setValue(currentUnit.convertFromPoint(
348 QLatin1String(
"fo:margin-top"), DEFAULT_PAGE_MARGIN_STRING))));
349 bottomMargin->setValue(currentUnit.convertFromPoint(
351 QLatin1String(
"fo:margin-bottom"), DEFAULT_PAGE_MARGIN_STRING))));
352 orientation->setValue(
354 QLatin1String(
"portrait")));
355 }
else if (n == QLatin1String(
"report:body")) {
359 for (
int s = 0; s < sectionlist.
count(); ++s) {
360 sec = sectionlist.
item(s);
364 if (sn == QLatin1String(
"report:section")) {
365 const QString sectiontype = KReportUtils::readSectionTypeNameAttribute(sec.
toElement());
370 }
else if (sn == QLatin1String(
"report:detail")) {
371 KReportDesignerSectionDetail * rsd =
new KReportDesignerSectionDetail(q);
376 kreportWarning() <<
"Encountered an unknown Element: " << n;
381 kreportWarning() <<
"Encountered a child node of root that is not an Element";
385 emit q->reportDataChanged();
386 q->slotPropertyChanged(set, *unit);
387 q->setModified(
false);
390#ifdef KREPORT_SCRIPTING
391void KReportDesigner::Private::updateScripts()
394 QStringList sl = scriptSource->scriptList();
396 script->setListData(sl, sl);
434 content.
appendChild(propertyToElement(&doc, d->title));
436#ifdef KREPORT_SCRIPTING
437 if (d->originalInterpreter.isEmpty()) {
440 saveInterpreter = d->originalInterpreter;
442 if (!d->script->value().toString().isEmpty()) {
443 if (d->script->value().toString() != d->originalScript || d->originalInterpreter ==
QLatin1String(
"qtscript") || d->originalInterpreter.isEmpty() ) {
449 QDomElement scr = propertyToElement(&doc, d->script);
455 KReportUtils::addPropertyAsAttribute(&grd, d->showGrid);
456 KReportUtils::addPropertyAsAttribute(&grd, d->gridDivisions);
457 KReportUtils::addPropertyAsAttribute(&grd, d->gridSnap);
458 KReportUtils::addPropertyAsAttribute(&grd, d->unit);
465 if (d->pageSize->value().toString() ==
QLatin1String(
"Custom")) {
468 KReportUtils::setAttribute(
470 d->currentUnit.convertToPoint(d->customPageSize->value().toSizeF().width()));
471 KReportUtils::setAttribute(
473 d->currentUnit.convertToPoint(d->customPageSize->value().toSizeF().height()));
474 }
else if (d->pageSize->value().toString() ==
QLatin1String(
"Label")) {
479 KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize);
484 KReportUtils::addPropertyAsAttribute(&pagestyle, d->orientation);
487 KReportUtils::setAttribute(
489 d->currentUnit.convertToPoint(d->topMargin->value().toDouble()));
490 KReportUtils::setAttribute(
492 d->currentUnit.convertToPoint(d->bottomMargin->value().toDouble()));
493 KReportUtils::setAttribute(
495 d->currentUnit.convertToPoint(d->rightMargin->value().toDouble()));
496 KReportUtils::setAttribute(
498 d->currentUnit.convertToPoint(d->leftMargin->value().toDouble()));
505 for (
int i =
static_cast<int>(KReportSectionData::Type::PageHeaderFirst);
506 i <= static_cast<int>(KReportSectionData::Type::PageFooterAny); ++i)
514 sec->buildXML(&doc, &domsection);
520 d->detail->buildXML(&doc, &detail);
527void KReportDesigner::slotSectionEditor()
529 KReportSectionEditor se(
this);
535 if (d->dataSource == source) {
538 delete d->dataSource;
540 d->dataSource = source;
541 slotPageButton_Pressed();
543 emit reportDataChanged();
546#ifdef KREPORT_SCRIPTING
549 d->scriptSource = source;
558 case KReportSectionData::Type::PageHeaderAny:
559 sec = d->pageHeaderAny;
561 case KReportSectionData::Type::PageHeaderEven:
562 sec = d->pageHeaderEven;
564 case KReportSectionData::Type::PageHeaderOdd:
565 sec = d->pageHeaderOdd;
567 case KReportSectionData::Type::PageHeaderFirst:
568 sec = d->pageHeaderFirst;
570 case KReportSectionData::Type::PageHeaderLast:
571 sec = d->pageHeaderLast;
573 case KReportSectionData::Type::PageFooterAny:
574 sec = d->pageFooterAny;
576 case KReportSectionData::Type::PageFooterEven:
577 sec = d->pageFooterEven;
579 case KReportSectionData::Type::PageFooterOdd:
580 sec = d->pageFooterOdd;
582 case KReportSectionData::Type::PageFooterFirst:
583 sec = d->pageFooterFirst;
585 case KReportSectionData::Type::PageFooterLast:
586 sec = d->pageFooterLast;
588 case KReportSectionData::Type::ReportHeader:
589 sec = d->reportHeader;
591 case KReportSectionData::Type::ReportFooter:
592 sec = d->reportFooter;
612 case KReportSectionData::Type::PageHeaderAny:
613 d->pageHeaderAny =
nullptr;
615 case KReportSectionData::Type::PageHeaderEven:
616 sec = d->pageHeaderEven =
nullptr;
618 case KReportSectionData::Type::PageHeaderOdd:
619 d->pageHeaderOdd =
nullptr;
621 case KReportSectionData::Type::PageHeaderFirst:
622 d->pageHeaderFirst =
nullptr;
624 case KReportSectionData::Type::PageHeaderLast:
625 d->pageHeaderLast =
nullptr;
627 case KReportSectionData::Type::PageFooterAny:
628 d->pageFooterAny =
nullptr;
630 case KReportSectionData::Type::PageFooterEven:
631 d->pageFooterEven =
nullptr;
633 case KReportSectionData::Type::PageFooterOdd:
634 d->pageFooterOdd =
nullptr;
636 case KReportSectionData::Type::PageFooterFirst:
637 d->pageFooterFirst =
nullptr;
639 case KReportSectionData::Type::PageFooterLast:
640 d->pageFooterLast =
nullptr;
642 case KReportSectionData::Type::ReportHeader:
643 d->reportHeader =
nullptr;
645 case KReportSectionData::Type::ReportFooter:
646 d->reportFooter =
nullptr;
662 for (
int i =
static_cast<int>(KReportSectionData::Type::PageHeaderFirst);
663 i <= static_cast<int>(type); ++i)
665 if (
section(
static_cast<KReportSectionData::Type
>(i)))
668 if (type > KReportSectionData::Type::ReportHeader)
672 d->vboxlayout->insertWidget(idx, rs);
675 case KReportSectionData::Type::PageHeaderAny:
676 rs->setTitle(
tr(
"Page Header (Any)"));
677 d->pageHeaderAny = rs;
679 case KReportSectionData::Type::PageHeaderEven:
680 rs->setTitle(
tr(
"Page Header (Even)"));
681 d->pageHeaderEven = rs;
683 case KReportSectionData::Type::PageHeaderOdd:
684 rs->setTitle(
tr(
"Page Header (Odd)"));
685 d->pageHeaderOdd = rs;
687 case KReportSectionData::Type::PageHeaderFirst:
688 rs->setTitle(
tr(
"Page Header (First)"));
689 d->pageHeaderFirst = rs;
691 case KReportSectionData::Type::PageHeaderLast:
692 rs->setTitle(
tr(
"Page Header (Last)"));
693 d->pageHeaderLast = rs;
695 case KReportSectionData::Type::PageFooterAny:
696 rs->setTitle(
tr(
"Page Footer (Any)"));
697 d->pageFooterAny = rs;
699 case KReportSectionData::Type::PageFooterEven:
700 rs->setTitle(
tr(
"Page Footer (Even)"));
701 d->pageFooterEven = rs;
703 case KReportSectionData::Type::PageFooterOdd:
704 rs->setTitle(
tr(
"Page Footer (Odd)"));
705 d->pageFooterOdd = rs;
707 case KReportSectionData::Type::PageFooterFirst:
708 rs->setTitle(
tr(
"Page Footer (First)"));
709 d->pageFooterFirst = rs;
711 case KReportSectionData::Type::PageFooterLast:
712 rs->setTitle(
tr(
"Page Footer (Last)"));
713 d->pageFooterLast = rs;
715 case KReportSectionData::Type::ReportHeader:
716 rs->setTitle(
tr(
"Report Header"));
717 d->reportHeader = rs;
719 case KReportSectionData::Type::ReportFooter:
720 rs->setTitle(
tr(
"Report Footer"));
721 d->reportFooter = rs;
724 case KReportSectionData::Type::None:
725 case KReportSectionData::Type::GroupHeader:
726 case KReportSectionData::Type::GroupFooter:
727 case KReportSectionData::Type::Detail:
734 emit pagePropertyChanged(d->set);
741 d->title->setValue(str);
758 return d->dataSource;
768 return d->title->value().toString();
778 d->modified = modified;
790 qs << d->dataSource->fieldNames();
800 qs << d->dataSource->fieldKeys();
805void KReportDesigner::createProperties()
808 tr(
"Report",
"Main report element"),
QLatin1String(
"kreport-report-element"));
818 d->pageSize =
new KProperty(
"page-size", listData, defaultKey,
tr(
"Page Size"));
820 d->customPageSize =
new KProperty(
"custom-page-size", DEFAULT_CUSTOM_PAGE_SIZE,
821 tr(
"Custom Page Size"),
tr(
"Custom Page Size"), KProperty::SizeF);
822 d->customPageSize->setOption(
"suffix", d->currentUnit.symbol());
825 QVariantList{
tr(
"Portrait"),
tr(
"Landscape") });
826 d->orientation =
new KProperty(
"print-orientation", listData, QLatin1String(
"portrait"),
827 tr(
"Page Orientation"));
830 types.removeOne(KReportUnit::Type::Pixel);
832 d->unit =
new KProperty(
"page-unit", listData, DEFAULT_UNIT_STRING,
tr(
"Page Unit"));
833 d->showGrid =
new KProperty(
"grid-visible",
true,
tr(
"Show Grid"));
834 d->gridSnap =
new KProperty(
"grid-snap",
true,
tr(
"Snap to Grid"));
835 d->gridDivisions =
new KProperty(
"grid-divisions", 4,
tr(
"Grid Divisions"));
836 d->gridDivisions->setOption(
"min", 1);
837 d->gridDivisions->setOption(
"max", 10);
841 tr(
"Left Margin"),
tr(
"Left Margin"), KProperty::Double);
843 tr(
"Right Margin"),
tr(
"Right Margin"), KProperty::Double);
845 tr(
"Top Margin"),
tr(
"Top Margin"), KProperty::Double);
847 tr(
"Bottom Margin"),
tr(
"Bottom Margin"), KProperty::Double);
848 d->leftMargin->setOption(
"suffix", d->currentUnit.symbol());
849 d->rightMargin->setOption(
"suffix", d->currentUnit.symbol());
850 d->topMargin->setOption(
"suffix", d->currentUnit.symbol());
851 d->bottomMargin->setOption(
"suffix", d->currentUnit.symbol());
853 d->set.addProperty(d->title);
854 d->set.addProperty(d->pageSize);
855 d->set.addProperty(d->customPageSize);
856 d->set.addProperty(d->orientation);
857 d->set.addProperty(d->unit);
858 d->set.addProperty(d->gridSnap);
859 d->set.addProperty(d->showGrid);
860 d->set.addProperty(d->gridDivisions);
861 d->set.addProperty(d->leftMargin);
862 d->set.addProperty(d->rightMargin);
863 d->set.addProperty(d->topMargin);
864 d->set.addProperty(d->bottomMargin);
866 recalculateMaxMargins();
868#ifdef KREPORT_SCRIPTING
869 d->script =
new KProperty(
"script",
new KPropertyListData, QVariant(),
tr(
"Object Script"));
870 d->set.addProperty(d->script);
879 const QSignalBlocker blocker(s);
881 QByteArray propertyName = p.
name();
883 if (propertyName ==
"page-unit") {
884 const KReportUnit oldUnit = d->currentUnit;
885 d->updateCurrentUnit();
890 d->leftMargin->value().toDouble(), oldUnit, d->currentUnit),
891 KProperty::ValueOption::IgnoreOld);
894 d->rightMargin->value().toDouble(), oldUnit, d->currentUnit),
895 KProperty::ValueOption::IgnoreOld);
898 oldUnit, d->currentUnit),
899 KProperty::ValueOption::IgnoreOld);
902 d->bottomMargin->value().toDouble(), oldUnit, d->currentUnit),
903 KProperty::ValueOption::IgnoreOld);
905 d->customPageSize->setValue(
908 KProperty::ValueOption::IgnoreOld);
910 d->leftMargin->setOption(
"suffix", d->currentUnit.symbol());
911 d->rightMargin->setOption(
"suffix", d->currentUnit.symbol());
912 d->topMargin->setOption(
"suffix", d->currentUnit.symbol());
913 d->bottomMargin->setOption(
"suffix", d->currentUnit.symbol());
914 d->customPageSize->setOption(
"suffix", d->currentUnit.symbol());
915 }
else if (propertyName.
startsWith(
"margin-") || propertyName ==
"page-size" || propertyName ==
"custom-page-size") {
916 recalculateMaxMargins();
918 emit pagePropertyChanged(s);
922void KReportDesigner::slotPageButton_Pressed()
924#ifdef KREPORT_SCRIPTING
935 if (d->pageFooterAny)
936 h += d->pageFooterAny->sizeHint().height();
937 if (d->pageFooterEven)
938 h += d->pageFooterEven->sizeHint().height();
939 if (d->pageFooterFirst)
940 h += d->pageFooterFirst->sizeHint().height();
941 if (d->pageFooterLast)
942 h += d->pageFooterLast->sizeHint().height();
943 if (d->pageFooterOdd)
944 h += d->pageFooterOdd->sizeHint().height();
945 if (d->pageHeaderAny)
946 h += d->pageHeaderAny->sizeHint().height();
947 if (d->pageHeaderEven)
948 h += d->pageHeaderEven->sizeHint().height();
949 if (d->pageHeaderFirst)
950 h += d->pageHeaderFirst->sizeHint().height();
951 if (d->pageHeaderLast)
952 h += d->pageHeaderLast->sizeHint().height();
953 if (d->pageHeaderOdd)
954 h += d->pageHeaderOdd->sizeHint().height();
956 h += d->reportHeader->sizeHint().height();
957 if (d->reportFooter) {
958 h += d->reportFooter->sizeHint().height();
962 h += d->detail->sizeHint().height();
963 w += d->detail->sizeHint().width();
966 h += d->hruler->height();
976 if (d->set.property(
"page-size").value().toString() ==
QLatin1String(
"Custom")) {
979 QSizeF customSize = d->currentUnit.convertToPoint(d->set.property(
"custom-page-size").value().toSizeF());
983 pageSizePx =
layout.fullRectPixels(KReportPrivate::dpiX()).size();
987 d->set.property(
"print-orientation").value().toString()
989 pageSizePx =
layout.fullRectPixels(KReportPrivate::dpiX()).size();
992 pageWidth = pageSizePx.
width();
1000QSize KReportDesigner::pageSizePt()
const
1007 QSizeF customSize = d->currentUnit.convertToPoint(d->set.property(
"custom-page-size").value().toSizeF());
1011 pageSizePt =
layout.fullRectPoints().size();
1013 QPageLayout
layout = QPageLayout(
1015 d->set.property(
"print-orientation").value().toString()
1017 pageSizePt =
layout.fullRectPoints().size();
1033 if (d->pageHeaderFirst) idx++;
1034 if (d->pageHeaderOdd) idx++;
1035 if (d->pageHeaderEven) idx++;
1036 if (d->pageHeaderLast) idx++;
1037 if (d->pageHeaderAny) idx++;
1038 if (d->reportHeader) idx++;
1040 d->vboxlayout->insertWidget(idx, d->detail);
1046 return d->currentUnit;
1051 d->showGrid->setValue(
QVariant(vis));
1052 d->gridDivisions->setValue(div);
1064 bool itemsSelected = selectionCount() > 0;
1065 if (itemsSelected) {
1068 connect(a, SIGNAL(triggered()),
this, SLOT(slotEditCut()));
1072 connect(a, SIGNAL(triggered()),
this, SLOT(slotEditCopy()));
1075 if (!d->sectionData.copy_list.isEmpty()) {
1077 connect(a, SIGNAL(triggered()),
this, SLOT(slotEditPaste()));
1081 if (itemsSelected) {
1096void KReportDesigner::sectionMousePressEvent(KReportDesignerSectionView * v,
QMouseEvent * e)
1099 d->pressX = e->
pos().
x();
1100 d->pressY = e->
pos().
y();
1107 d->releaseX = e->
pos().
x();
1108 d->releaseY = e->
pos().
y();
1112 QPointF end(d->releaseX, d->releaseY);
1123 if (d->sectionData.mouseAction == ReportWriterSectionData::MouseAction::Insert) {
1127 if (d->sectionData.itemToInsert ==
QLatin1String(
"org.kde.kreport.line")) {
1128 item =
new KReportDesignerItemLine(v->designer(), v->
scene(),
pos, end);
1129 classString =
tr(
"Line",
"Report line element");
1136 QObject *obj = plug->createDesignerInstance(v->designer(), v->
scene(),
pos);
1144 kreportWarning() <<
"attempted to insert an unknown item";
1151 if (baseReportItem) {
1156 if (v && v->designer()) {
1159 emit itemInserted(d->sectionData.itemToInsert);
1163 d->sectionData.mouseAction = ReportWriterSectionData::MouseAction::None;
1164 d->sectionData.itemToInsert.
clear();
1165 unsetSectionCursor();
1170unsigned int KReportDesigner::selectionCount()
const
1186 if (d->itemSet != set) {
1188 emit propertySetChanged();
1196void KReportDesigner::slotItem(
const QString &entity)
1199 d->sectionData.mouseAction = ReportWriterSectionData::MouseAction::Insert;
1200 d->sectionData.itemToInsert = entity;
1207 bool modified =
false;
1208 while (selectionCount() > 0) {
1214 d->sectionData.mouseAction = ReportWriterSectionData::MouseAction::None;
1224 d->sectionData.cut_list.clear();
1225 d->sectionData.copy_list.clear();
1231void KReportDesigner::slotEditCut()
1233 if (selectionCount() > 0) {
1236 qDeleteAll(d->sectionData.cut_list);
1237 d->sectionData.cut_list.
clear();
1240 bool modified =
false;
1242 d->sectionData.copy_list.
clear();
1247 foreach(QGraphicsItem *item,
activeScene()->selectedItems()) {
1252 d->sectionData.selected_x_offset = 10;
1253 d->sectionData.selected_y_offset = 10;
1261void KReportDesigner::slotEditCopy()
1263 if (selectionCount() < 1)
1268 d->sectionData.copy_list.clear();
1269 foreach(QGraphicsItem *item,
activeScene()->selectedItems()) {
1270 d->sectionData.copy_list.append(
dynamic_cast<KReportDesignerItemBase*
>(item));
1272 d->sectionData.selected_x_offset = 10;
1273 d->sectionData.selected_y_offset = 10;
1277void KReportDesigner::slotEditPaste()
1287 if (!d->sectionData.copy_list.isEmpty()) {
1290 if (activeItems.
count() == 1) {
1291 activeItem = activeItems.
first();
1294 d->sectionData.mouseAction = ReportWriterSectionData::MouseAction::None;
1320 d->sectionData.mouseAction = ReportWriterSectionData::MouseAction::Grab;
1326void KReportDesigner::slotRaiseSelected()
1328 dynamic_cast<KReportDesignerSectionScene*
>(
activeScene())->raiseSelected();
1331void KReportDesigner::slotLowerSelected()
1333 dynamic_cast<KReportDesignerSectionScene*
>(
activeScene())->lowerSelected();
1338 return d->activeScene;
1343 if (d->activeScene && d->activeScene != a)
1356 for (
int i =
static_cast<int>(KReportSectionData::Type::PageHeaderFirst);
1357 i <= static_cast<int>(KReportSectionData::Type::PageFooterAny); i++)
1359 sec =
section(
static_cast<KReportSectionData::Type
>(i));
1361 const QGraphicsItemList l = sec->
items();
1362 itemCount += l.
count();
1368 for (
int i = 0; i < d->detail->groupSectionCount(); i++) {
1369 sec = d->detail->groupSection(i)->groupHeader();
1371 const QGraphicsItemList l = sec->
items();
1372 itemCount += l.
count();
1374 sec = d->detail->groupSection(i)->groupFooter();
1376 const QGraphicsItemList l = sec->
items();
1377 itemCount += l.
count();
1381 sec = d->detail->detailSection();
1383 const QGraphicsItemList l = sec->
items();
1384 itemCount += l.
count();
1400 for (
int i =
static_cast<int>(KReportSectionData::Type::PageHeaderFirst);
1401 i <= static_cast<int>(KReportSectionData::Type::PageFooterAny); i++)
1403 sec =
section(
static_cast<KReportSectionData::Type
>(i));
1405 const QGraphicsItemList l = sec->
items();
1406 for (QGraphicsItemList::const_iterator it = l.
constBegin(); it != l.
constEnd(); ++it) {
1408 if (itm && itm->entityName() == name && itm != ignore) {
1418 if (unique && d->detail) {
1419 for (
int i = 0; i < d->detail->groupSectionCount(); ++i) {
1420 sec = d->detail->groupSection(i)->groupHeader();
1422 const QGraphicsItemList l = sec->
items();
1423 for (QGraphicsItemList::const_iterator it = l.
constBegin(); it != l.
constEnd(); ++it) {
1425 if (itm && itm->entityName() == name && itm != ignore) {
1432 sec = d->detail->groupSection(i)->groupFooter();
1433 if (unique && sec) {
1434 const QGraphicsItemList l = sec->
items();
1435 for (QGraphicsItemList::const_iterator it = l.
constBegin(); it != l.
constEnd(); ++it) {
1437 if (itm && itm->entityName() == name && itm != ignore) {
1445 if (unique && d->detail) {
1446 sec = d->detail->detailSection();
1448 const QGraphicsItemList l = sec->
items();
1449 for (QGraphicsItemList::const_iterator it = l.
constBegin(); it != l.
constEnd(); ++it) {
1451 if (itm && itm->entityName() == name && itm != ignore) {
1482 std::sort(actList.
begin(), actList.
end(), actionPriortyLessThan);
1489 bool sepInserted =
false;
1490 foreach(
QAction *a, actList) {
1492 if (!sepInserted && a->
data().
toInt() >= 10) {
1495 actList.
insert(i-1, sep);
1512 al << d->editCutAction << d->editCopyAction << d->editPasteAction << d->editDeleteAction << sep << d->sectionEdit << sep << d->itemLowerAction << d->itemRaiseAction;
1517void KReportDesigner::createActions()
1521 d->editCutAction->setToolTip(
tr(
"Cut selection to clipboard"));
1523 d->editCutAction->setProperty(
"iconOnly",
true);
1526 d->editCopyAction->setObjectName(
QLatin1String(
"edit_copy"));
1527 d->editCopyAction->setToolTip(
tr(
"Copy selection to clipboard"));
1529 d->editCopyAction->setProperty(
"iconOnly",
true);
1532 d->editPasteAction->setObjectName(
QLatin1String(
"edit_paste"));
1533 d->editPasteAction->setToolTip(
tr(
"Paste clipboard content"));
1535 d->editPasteAction->setProperty(
"iconOnly",
true);
1539 d->editDeleteAction->setObjectName(
QLatin1String(
"edit_delete"));
1540 d->editDeleteAction->setToolTip(del.
toolTip());
1541 d->editDeleteAction->setWhatsThis(del.
whatsThis());
1542 d->editDeleteAction->setProperty(
"iconOnly",
true);
1544 d->sectionEdit =
new QAction(
tr(
"Edit Sections"),
this);
1545 d->sectionEdit->setObjectName(
QLatin1String(
"section_edit"));
1548 d->itemRaiseAction->setObjectName(
QLatin1String(
"item_raise"));
1550 d->itemLowerAction->setObjectName(
QLatin1String(
"item_lower"));
1553 connect(d->editCutAction, SIGNAL(triggered(
bool)),
this, SLOT(slotEditCut()));
1554 connect(d->editCopyAction, SIGNAL(triggered(
bool)),
this, SLOT(slotEditCopy()));
1555 connect(d->editPasteAction, SIGNAL(triggered(
bool)),
this, SLOT(slotEditPaste()));
1558 connect(d->sectionEdit, SIGNAL(triggered(
bool)),
this, SLOT(slotSectionEditor()));
1561 connect(d->itemRaiseAction, SIGNAL(triggered(
bool)),
this, SLOT(slotRaiseSelected()));
1562 connect(d->itemLowerAction, SIGNAL(triggered(
bool)),
this, SLOT(slotLowerSelected()));
1565void KReportDesigner::setSectionCursor(
const QCursor& c)
1567 if (d->pageFooterAny)
1568 d->pageFooterAny->setSectionCursor(c);
1569 if (d->pageFooterEven)
1570 d->pageFooterEven->setSectionCursor(c);
1571 if (d->pageFooterFirst)
1572 d->pageFooterFirst->setSectionCursor(c);
1573 if (d->pageFooterLast)
1574 d->pageFooterLast->setSectionCursor(c);
1575 if (d->pageFooterOdd)
1576 d->pageFooterOdd->setSectionCursor(c);
1578 if (d->pageHeaderAny)
1579 d->pageHeaderAny->setSectionCursor(c);
1580 if (d->pageHeaderEven)
1581 d->pageHeaderEven->setSectionCursor(c);
1582 if (d->pageHeaderFirst)
1583 d->pageHeaderFirst->setSectionCursor(c);
1584 if (d->pageHeaderLast)
1585 d->pageHeaderLast->setSectionCursor(c);
1586 if (d->pageHeaderOdd)
1587 d->pageHeaderOdd->setSectionCursor(c);
1590 d->detail->setSectionCursor(c);
1593void KReportDesigner::unsetSectionCursor()
1595 if (d->pageFooterAny)
1596 d->pageFooterAny->unsetSectionCursor();
1597 if (d->pageFooterEven)
1598 d->pageFooterEven->unsetSectionCursor();
1599 if (d->pageFooterFirst)
1600 d->pageFooterFirst->unsetSectionCursor();
1601 if (d->pageFooterLast)
1602 d->pageFooterLast->unsetSectionCursor();
1603 if (d->pageFooterOdd)
1604 d->pageFooterOdd->unsetSectionCursor();
1606 if (d->pageHeaderAny)
1607 d->pageHeaderAny->unsetSectionCursor();
1608 if (d->pageHeaderEven)
1609 d->pageHeaderEven->unsetSectionCursor();
1610 if (d->pageHeaderFirst)
1611 d->pageHeaderFirst->unsetSectionCursor();
1612 if (d->pageHeaderLast)
1613 d->pageHeaderLast->unsetSectionCursor();
1614 if (d->pageHeaderOdd)
1615 d->pageHeaderOdd->unsetSectionCursor();
1618 d->detail->unsetSectionCursor();
1623 if (d->releaseY == -1 || d->pressY == -1) {
1626 return qAbs(d->releaseY - d->pressY);
1631 if (d->releaseX == -1 || d->pressX == -1) {
1634 return qAbs(d->releaseX - d->pressX);
1649 return QPointF(d->pressX, d->pressY);
1654 return QPointF(d->releaseX, d->releaseY);
1659 foreach(
QAction *a, actList) {
1660 connect(a, SIGNAL(triggered(
bool)),
this, SLOT(slotItemTriggered(
bool)));
1664void KReportDesigner::slotItemTriggered(
bool checked)
1687void KReportDesigner::recalculateMaxMargins()
1689 QSize pageSize = pageSizePt();
1690 d->leftMargin->setOption(
"max", d->currentUnit.convertFromPoint(pageSize.width() - d->currentUnit.convertToPoint(d->rightMargin->value().toReal()) - SMALLEST_PAGE_SIZE_PT));
1691 d->rightMargin->setOption(
"max", d->currentUnit.convertFromPoint(pageSize.width() - d->currentUnit.convertToPoint(d->leftMargin->value().toReal())- SMALLEST_PAGE_SIZE_PT));
1692 d->topMargin->setOption(
"max", d->currentUnit.convertFromPoint(pageSize.height() - d->currentUnit.convertToPoint(d->bottomMargin->value().toReal())- SMALLEST_PAGE_SIZE_PT));
1693 d->bottomMargin->setOption(
"max", d->currentUnit.convertFromPoint(pageSize.height() - d->currentUnit.convertToPoint(d->topMargin->value().toReal())- SMALLEST_PAGE_SIZE_PT));
QString whatsThis() const
void addProperty(KProperty *property, const QByteArray &group="common")
void clearModifiedFlags()
void propertyChanged(KPropertySet &set, KProperty &property)
void setVisible(bool visible)
Abstraction of report data source.
Base class for report items used within the designer GUI.
The central detail section which contains the bulk of the report.
void initFromXML(QDomNode *node)
This class is the base to all Report Section's visual representation.
QGraphicsItemList items() const
Return the items in the section Only return top-level items ... ie, items with no parent item because...
The ReportDesigner is the main widget for designing a report.
void sectionMouseReleaseEvent(KReportDesignerSectionView *v, QMouseEvent *e)
Handle the mouse release event for a report section.
KReportDataSource * reportDataSource() const
Return a pointer to the reports data.
KReportDesignerSectionDetail * detailSection() const
Return a pointer to the detail section.
KReportUnit pageUnit() const
Return the current unit assigned to the report.
QList< QAction * > designerActions()
Populates the toolbar with actions that can be applied to the report Actions are created as children ...
QString suggestEntityName(const QString &name) const
Return a unique name that can be used by the entity.
bool isEntityNameUnique(const QString &name, KReportItemBase *ignore=nullptr) const
Checks if the supplied name is unique among all entities.
bool isModified() const
Return true if the design has been modified.
int pageWidthPx() const
Calculate the width of the page in pixels given the paper size, orientation, dpi and margin.
void setActiveScene(QGraphicsScene *scene)
Sets the active Scene.
void setDataSource(KReportDataSource *source)
Sets the report data The report data interface contains functions to retrieve data and information ab...
void setReportTitle(const QString &title)
Sets the title of the reportData.
void sectionContextMenuEvent(KReportDesignerSectionScene *scene, QGraphicsSceneContextMenuEvent *event)
Handle the context menu event for a report section.
QSize sizeHint() const override
Give a hint on the size of the widget.
void insertSection(KReportSectionData::Type type)
Create a new section and insert it into the report.
static QList< QAction * > itemActions(QActionGroup *group=nullptr)
Returns a list of actions that represent the entities that can be inserted into the report.
QString reportTitle() const
Return the title of the report.
void setGridOptions(bool visible, int divisions)
Sets the parameters for the display of the background gridpoints.
void setModified(bool modified)
Sets the modified status, defaulting to true for modified.
~KReportDesigner() override
Desctructor.
qreal getSelectionPressY() const
qreal getSelectionPressX() const
KReportDesignerSection * section(KReportSectionData::Type type) const
Return a pointer to the section specified.
QGraphicsScene * activeScene() const
QPointF getReleasePoint() const
KReportDesigner(QWidget *parent=nullptr)
Constructor that create a blank designer.
void changeSet(KPropertySet *set)
Sets the property set for the currently selected item.
qreal countSelectionHeight() const
KPropertySet * selectedItemPropertySet() const
Return the property set for the curently selected item.
QStringList fieldKeys() const
void removeSection(KReportSectionData::Type type)
Deletes the section specified.
QDomElement document() const
Return an XML description of the report.
QStringList fieldNames() const
KReportDesignerSection * createSection()
Creates new section.
KPropertySet * propertySet() const
static void addMetaProperties(KPropertySet *set, const QString &classString, const QString &iconName)
Adds meta-properties to the property set set for consumption by property editor.
QPointF getPressPoint() const
qreal countSelectionWidth() const
Base class for items that are drawn syncronously.
void setPosition(const QPointF &ptPos)
Sets position for the element.
static QPointF positionFromScene(const QPointF &pos)
Helper function mapping from screen units to points, pos is in pixels.
virtual QString typeName() const =0
Return the item type as a string.
An interface for plugins delivering KReport elements.
const KReportPluginMetaData * metaData() const
Manager class for finding and loading available plugins.
Abstraction of report script source.
static KReportSectionData::Type sectionTypeFromString(const QString &s)
static QString sectionTypeString(KReportSectionData::Type type)
Converts between different units.
static KReportUnit::Type symbolToType(const QString &symbol)
Returns a unit symbol string to type.
static qreal convertFromUnitToUnit(qreal value, const KReportUnit &fromUnit, const KReportUnit &toUnit, qreal factor=1.0)
convert the given value directly from one unit to another with high accuracy
static QList< Type > allTypes()
Returns list of all supported types (without Invalid)
bool isValid() const
Returns true if type of this unit is valid.
static QStringList symbols(const QList< Type > &types)
Returns the list of unit symbols for the given types.
static qreal parseValue(const QString &value, qreal defaultVal=0.0)
Parses common KReport and ODF values, like "10cm", "5mm" to pt.
static QStringList descriptions(const QList< Type > &types)
Returns the list of (translated) description strings for given list of types.
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
KREPORT_EXPORT QString pageSizeKey(QPageSize::PageSizeId id)
KREPORT_EXPORT QPageSize::PageSizeId pageSize(const QString &key)
KREPORT_EXPORT QStringList pageFormatKeys()
KREPORT_EXPORT QPageSize::PageSizeId defaultSize()
KREPORT_EXPORT QStringList pageFormatNames()
const QList< QKeySequence > & cut()
const QList< QKeySequence > & paste()
const QList< QKeySequence > & copy()
QVariant data() const const
void setData(const QVariant &data)
void setSeparator(bool b)
QAction * addAction(QAction *action)
bool startsWith(QByteArrayView bv) const const
QByteArray toLower() const const
QDomElement createElement(const QString &tagName)
QDomText createTextNode(const QString &value)
QString toString(int indent) const const
QString attribute(const QString &name, const QString &defValue) const const
void setAttribute(const QString &name, const QString &value)
QString tagName() const const
QDomNode appendChild(const QDomNode &newChild)
QDomNodeList childNodes() const const
QDomNode firstChild() const const
bool isElement() const const
QString nodeName() const const
QString nodeValue() const const
QDomElement toElement() const const
QDomNode item(int index) const const
QGraphicsScene * scene() const const
void setSelected(bool selected)
void setVisible(bool visible)
void addItem(QGraphicsItem *item)
qreal height() const const
void removeItem(QGraphicsItem *item)
QList< QGraphicsItem * > selectedItems() const const
void update(const QRectF &rect)
qreal width() const const
QGraphicsScene * scene() const const
QIcon fromTheme(const QString &name)
const_iterator constBegin() const const
const_iterator constEnd() const const
qsizetype count() const const
iterator insert(const_iterator before, parameter_type value)
bool isEmpty() const const
void prepend(parameter_type value)
T value(qsizetype i) const const
StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool event(QEvent *e)
QObject * parent() const const
QObject * sender() const const
void setObjectName(QAnyStringView name)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)
QString toLower() const const
int toInt(bool *ok) const const
QString toString() const const