diff --git a/src/common/KReportItemBase.cpp b/src/common/KReportItemBase.cpp --- a/src/common/KReportItemBase.cpp +++ b/src/common/KReportItemBase.cpp @@ -35,7 +35,7 @@ KProperty *sizeProperty; KProperty *positionProperty; QString oldName; - qreal z; + qreal z = 0; }; KReportItemBase::Private::Private() @@ -59,9 +59,7 @@ KReportItemBase::KReportItemBase() : d(new Private()) -{ - d->z = 0; - +{ connect(propertySet(), &KPropertySet::propertyChanged, this, &KReportItemBase::propertyChanged); } diff --git a/src/common/KReportItemLine.cpp b/src/common/KReportItemLine.cpp --- a/src/common/KReportItemLine.cpp +++ b/src/common/KReportItemLine.cpp @@ -131,10 +131,12 @@ if (page) page->insertPrimitive(ln); OROLine *l2 = dynamic_cast(ln->clone()); - l2->setStartPoint(m_start->value().toPointF()); - l2->setEndPoint(m_end->value().toPointF()); - if (section) section->addPrimitive(l2); - + if (l2) { + l2->setStartPoint(m_start->value().toPointF()); + l2->setEndPoint(m_end->value().toPointF()); + + if (section) section->addPrimitive(l2); + } return 0; } diff --git a/src/common/KReportRenderObjects.cpp b/src/common/KReportRenderObjects.cpp --- a/src/common/KReportRenderObjects.cpp +++ b/src/common/KReportRenderObjects.cpp @@ -290,16 +290,15 @@ ~Private(); ORODocument * document; QList primitives; - qint64 row; - int height; - KReportSectionData::Section type; - QColor backgroundColor; + qint64 row = 0; + int height = 0; + KReportSectionData::Section type = KReportSectionData::None; + QColor backgroundColor = Qt::white; }; OROSection::Private::Private() { - height = 0; - backgroundColor = Qt::white; + } OROSection::Private::~Private() @@ -405,15 +404,14 @@ class Q_DECL_HIDDEN OROPrimitive::Private { public: - OROPage * page; + OROPage * page = nullptr; QPointF position; QSizeF size; }; OROPrimitive::OROPrimitive() : d(new Private()) { - d->page = 0; } OROPrimitive::~OROPrimitive() diff --git a/src/common/KReportUtils_p.cpp b/src/common/KReportUtils_p.cpp --- a/src/common/KReportUtils_p.cpp +++ b/src/common/KReportUtils_p.cpp @@ -50,8 +50,8 @@ m_dpiX = w->logicalDpiX(); m_dpiY = w->logicalDpiY(); } else { - m_dpiX = 75; - m_dpiY = 75; + m_dpiX = 96; + m_dpiY = 96; } #endif } diff --git a/src/items/check/KReportItemCheck.cpp b/src/items/check/KReportItemCheck.cpp --- a/src/items/check/KReportItemCheck.cpp +++ b/src/items/check/KReportItemCheck.cpp @@ -170,8 +170,10 @@ if (section) { OROCheckBox *chk2 = dynamic_cast(chk->clone()); - chk2->setPosition(scenePosition(position())); - section->addPrimitive(chk2); + if (chk2) { + chk2->setPosition(scenePosition(position())); + section->addPrimitive(chk2); + } } if (!page) { diff --git a/src/items/image/KReportItemImage.cpp b/src/items/image/KReportItemImage.cpp --- a/src/items/image/KReportItemImage.cpp +++ b/src/items/image/KReportItemImage.cpp @@ -174,8 +174,10 @@ if (section) { OROImage *i2 = dynamic_cast(id->clone()); - i2->setPosition(scenePosition(position())); - section->addPrimitive(i2); + if (i2) { + i2->setPosition(scenePosition(position())); + section->addPrimitive(i2); + } } if (!page) { diff --git a/src/items/text/KReportItemText.cpp b/src/items/text/KReportItemText.cpp --- a/src/items/text/KReportItemText.cpp +++ b/src/items/text/KReportItemText.cpp @@ -270,8 +270,10 @@ if (section) { OROTextBox *tb2 = dynamic_cast(tb->clone()); - tb2->setPosition(scenePosition(position())); - section->addPrimitive(tb2); + if (tb2) { + tb2->setPosition(scenePosition(position())); + section->addPrimitive(tb2); + } } if (!page) { diff --git a/src/renderer/KReportHTMLCSSRenderer_p.cpp b/src/renderer/KReportHTMLCSSRenderer_p.cpp --- a/src/renderer/KReportHTMLCSSRenderer_p.cpp +++ b/src/renderer/KReportHTMLCSSRenderer_p.cpp @@ -121,9 +121,7 @@ for (int i = 0; i < section->primitiveCount(); i++) { OROPrimitive * prim = section->primitive(i); //kreportDebug() << "Got object type" << prim->type(); - if (dynamic_cast(prim)) { - OROTextBox * tb = dynamic_cast(prim); - + if (OROTextBox *tb = dynamic_cast(prim)) { QColor bg = tb->textStyle().backgroundColor; style = QLatin1String("position: absolute; ") + QLatin1String("background-color: ") + QString::fromLatin1("rgba(%1,%2,%3,%4)") @@ -151,9 +149,7 @@ body += QLatin1String("
") + tb->text() + QLatin1String("
\n"); - } else if (dynamic_cast(prim)) { - //kreportDebug() << "Saving an image"; - OROImage * im = dynamic_cast(prim); + } else if (OROImage *im = dynamic_cast(prim)) { style = QLatin1String("position: absolute; ") + QLatin1String("top: ") + QString::number(im->position().y()) + QLatin1String("pt; ") + QLatin1String("left: ") + QString::number(im->position().x()) + QLatin1String("pt; "); @@ -168,9 +164,7 @@ im->image().save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); - } else if (dynamic_cast(prim)) { - //kreportDebug() << "Saving a picture"; - OROPicture * im = dynamic_cast(prim); + } else if (OROPicture *im = dynamic_cast(prim)) { style = QLatin1String("position: absolute; ") + QLatin1String("top: ") + QString::number(im->position().y()) + QLatin1String("pt; ") + QLatin1String("left: ") + QString::number(im->position().x()) + QLatin1String("pt; "); diff --git a/src/renderer/KReportHTMLTableRenderer_p.cpp b/src/renderer/KReportHTMLTableRenderer_p.cpp --- a/src/renderer/KReportHTMLTableRenderer_p.cpp +++ b/src/renderer/KReportHTMLTableRenderer_p.cpp @@ -115,23 +115,16 @@ for (int i = 0; i < section->primitiveCount(); i++) { OROPrimitive * prim = section->primitive(i); - if (dynamic_cast(prim)) { - OROTextBox * tb = dynamic_cast(prim); - + if (OROTextBox *tb = dynamic_cast(prim)) { tr += QLatin1String("") + tb->text() + QLatin1String("\n"); - } else if (dynamic_cast(prim)) { - //kreportDebug() << "Saving an image"; - OROImage * im = dynamic_cast(prim); + } else if (OROImage *im = dynamic_cast(prim)) { tr += QLatin1String("" "" "\n"); im->image().save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); - } else if (dynamic_cast(prim)) { - //kreportDebug() << "Saving a picture"; - OROPicture * im = dynamic_cast(prim); - + } else if (OROPicture *im = dynamic_cast(prim)) { tr += QLatin1String("" "" "\n"); diff --git a/src/renderer/KReportPage.cpp b/src/renderer/KReportPage.cpp --- a/src/renderer/KReportPage.cpp +++ b/src/renderer/KReportPage.cpp @@ -34,20 +34,18 @@ public: explicit Private(ORODocument *document) : reportDocument(document) - , page(0) {} ~Private() { delete renderer; } ORODocument *reportDocument; - int page; + int page = 0; QPixmap pixmap; KReportRendererFactory factory; KReportRendererBase *renderer; - QTimer renderTimer; }; diff --git a/src/renderer/KReportPreRenderer.cpp b/src/renderer/KReportPreRenderer.cpp --- a/src/renderer/KReportPreRenderer.cpp +++ b/src/renderer/KReportPreRenderer.cpp @@ -368,8 +368,7 @@ } for (int i = 0; i < m_page->primitiveCount(); ++i) { OROPrimitive *prim = m_page->primitive(i); - if (dynamic_cast(prim)) { - OROTextBox *text = dynamic_cast(prim); + if (OROTextBox *text = dynamic_cast(prim)) { if (text->requiresPostProcessing()) { m_postProcText.append(text); } diff --git a/src/renderer/KReportPrintRenderer_p.cpp b/src/renderer/KReportPrintRenderer_p.cpp --- a/src/renderer/KReportPrintRenderer_p.cpp +++ b/src/renderer/KReportPrintRenderer_p.cpp @@ -101,10 +101,7 @@ prim->setPosition(QPointF(prim->position().x() * scaleX, prim->position().y() * scaleY)); prim->setSize(QSizeF(prim->size().width() * scaleX, prim->size().height() * scaleY)); //kreportDebug() << "Rendering object" << i << "type" << prim->type(); - if (dynamic_cast(prim)) { - //kreportDebug() << "Text Box"; - OROTextBox * tb = dynamic_cast(prim); - + if (OROTextBox *tb = dynamic_cast(prim)) { QPointF ps = tb->position(); QSizeF sz = tb->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); @@ -131,9 +128,7 @@ //Reset back to defaults for next element context.painter()->restore(); - } else if (dynamic_cast(prim)) { - //kreportDebug() << "Line"; - OROLine * ln = dynamic_cast(prim); + } else if (OROLine *ln = dynamic_cast(prim)) { QPointF s = ln->startPoint(); QPointF e(ln->endPoint().x() * scaleX, ln->endPoint().y() * scaleY); //QPen pen ( _painter()->pen() ); @@ -145,9 +140,7 @@ context.painter()->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); context.painter()->setRenderHint(QPainter::Antialiasing, false); context.painter()->restore(); - } else if (dynamic_cast(prim)) { - //kreportDebug() << "Image"; - OROImage * im = dynamic_cast(prim); + } else if (OROImage *im = dynamic_cast(prim)) { QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); @@ -158,10 +151,7 @@ QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); context.painter()->drawImage(rc.topLeft(), img, sr); - } else if (dynamic_cast(prim)) { - //kreportDebug() << "Rect"; - ORORect * re = dynamic_cast(prim); - + } else if (ORORect *re = dynamic_cast(prim)) { QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); @@ -171,9 +161,7 @@ context.painter()->setBrush(re->brush()); context.painter()->drawRect(rc); context.painter()->restore(); - } else if (dynamic_cast(prim)) { - OROEllipse * re = dynamic_cast(prim); - + } else if (OROEllipse *re = dynamic_cast(prim)) { QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); @@ -183,14 +171,12 @@ context.painter()->setBrush(re->brush()); context.painter()->drawEllipse(rc); context.painter()->restore(); - } else if (dynamic_cast(prim)) { - OROPicture * im = dynamic_cast(prim); + } else if (OROPicture *im = dynamic_cast(prim)) { QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->drawPicture(rc.topLeft(), *(im->picture())); - } else if (dynamic_cast(prim)) { - OROCheckBox * chk = dynamic_cast(prim); + } else if (OROCheckBox *chk = dynamic_cast(prim)) { QPointF ps = chk->position(); QSizeF sz = chk->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); diff --git a/src/renderer/KReportScreenRenderer_p.cpp b/src/renderer/KReportScreenRenderer_p.cpp --- a/src/renderer/KReportScreenRenderer_p.cpp +++ b/src/renderer/KReportScreenRenderer_p.cpp @@ -50,9 +50,7 @@ for (int i = 0; i < p->primitiveCount(); i++) { OROPrimitive *prim = p->primitive(i); - if (dynamic_cast(prim)) { - OROTextBox *tb = dynamic_cast(prim); - + if (OROTextBox *tb = dynamic_cast(prim)) { QPointF ps = tb->position(); QSizeF sz = tb->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); @@ -79,8 +77,7 @@ //Reset back to defaults for next element context.painter()->restore(); } - else if (dynamic_cast(prim)) { - OROLine * ln = dynamic_cast(prim); + else if (OROLine *ln = dynamic_cast(prim)) { QPointF s = ln->startPoint(); QPointF e = ln->endPoint(); //QPen pen ( _painter->pen() ); @@ -93,9 +90,7 @@ context.painter()->setRenderHint(QPainter::Antialiasing, false); context.painter()->restore(); } - else if (dynamic_cast(prim)) { - ORORect * re = dynamic_cast(prim); - + else if (ORORect *re = dynamic_cast(prim)) { QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); @@ -106,9 +101,7 @@ context.painter()->drawRect(rc); context.painter()->restore(); } - else if (dynamic_cast(prim)) { - OROEllipse * re = dynamic_cast(prim); - + else if (OROEllipse *re = dynamic_cast(prim)) { QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); @@ -119,8 +112,7 @@ context.painter()->drawEllipse(rc); context.painter()->restore(); } - else if (dynamic_cast(prim)) { - OROImage * im = dynamic_cast(prim); + else if ( OROImage *im = dynamic_cast(prim)) { QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); @@ -133,17 +125,15 @@ QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); context.painter()->drawImage(rc.topLeft(), img, sr); } - else if (dynamic_cast(prim)) { - OROPicture * im = dynamic_cast(prim); + else if (OROPicture *im = dynamic_cast(prim)) { QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter()->save(); context.painter()->drawPicture(rc.topLeft(), *(im->picture())); context.painter()->restore(); } - else if (dynamic_cast(prim)) { - OROCheckBox * chk = dynamic_cast(prim); + else if (OROCheckBox *chk = dynamic_cast(prim)) { QPointF ps = chk->position(); QSizeF sz = chk->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); diff --git a/src/renderer/scripting/KReportScriptHandler.cpp b/src/renderer/scripting/KReportScriptHandler.cpp --- a/src/renderer/scripting/KReportScriptHandler.cpp +++ b/src/renderer/scripting/KReportScriptHandler.cpp @@ -42,33 +42,18 @@ KReportScriptConstants *constants; KReportScriptDebug *debug; KReportScriptDraw *draw; - Scripting::Report *report; - const KReportData *reportData; - QString source; KReportDocument *reportDocument; - QJSEngine engine; QJSValue scriptValue; - QMap groups; QMap sectionMap; }; -KReportScriptHandler::Private::Private() +KReportScriptHandler::Private::Private() : constants(new KReportScriptConstants), debug(new KReportScriptDebug), draw(new KReportScriptDraw) { - //NOTE these are on the heap so that engine can delete them - - //Add constants object - constants = new KReportScriptConstants(); - - //A simple debug function to allow printing from functions - debug = new KReportScriptDebug(); - - //A simple drawing object - draw = new KReportScriptDraw(); } KReportScriptHandler::Private::~Private() diff --git a/src/wrtembed/KReportDesigner.cpp b/src/wrtembed/KReportDesigner.cpp --- a/src/wrtembed/KReportDesigner.cpp +++ b/src/wrtembed/KReportDesigner.cpp @@ -106,28 +106,7 @@ class Q_DECL_HIDDEN KReportDesigner::Private { public: - Private() - : activeScene(0) - , reportHeader(0) - , pageHeaderFirst(0) - , pageHeaderOdd(0) - , pageHeaderEven(0) - , pageHeaderLast(0) - , pageHeaderAny(0) - , pageFooterFirst(0) - , pageFooterOdd(0) - , pageFooterEven(0) - , pageFooterLast(0) - , pageFooterAny(0) - , reportFooter(0) - , detail(0) - , pressX(-1) - , pressY(-1) - , releaseX(-1) - , releaseY(-1) - , modified(false) - , kordata(0) - {} + Private(){} ~Private() { @@ -143,24 +122,24 @@ QVBoxLayout *vboxlayout; KReportPropertiesButton *pageButton; - QGraphicsScene *activeScene; + QGraphicsScene *activeScene = nullptr; ReportWriterSectionData *sectionData; - KReportDesignerSection *reportHeader; - KReportDesignerSection *pageHeaderFirst; - KReportDesignerSection *pageHeaderOdd; - KReportDesignerSection *pageHeaderEven; - KReportDesignerSection *pageHeaderLast; - KReportDesignerSection *pageHeaderAny; - - KReportDesignerSection *pageFooterFirst; - KReportDesignerSection *pageFooterOdd; - KReportDesignerSection *pageFooterEven; - KReportDesignerSection *pageFooterLast; - KReportDesignerSection *pageFooterAny; - KReportDesignerSection *reportFooter; - KReportDesignerSectionDetail *detail; + KReportDesignerSection *reportHeader = nullptr; + KReportDesignerSection *pageHeaderFirst = nullptr; + KReportDesignerSection *pageHeaderOdd = nullptr; + KReportDesignerSection *pageHeaderEven = nullptr; + KReportDesignerSection *pageHeaderLast = nullptr; + KReportDesignerSection *pageHeaderAny = nullptr; + + KReportDesignerSection *pageFooterFirst = nullptr; + KReportDesignerSection *pageFooterOdd = nullptr; + KReportDesignerSection *pageFooterEven = nullptr; + KReportDesignerSection *pageFooterLast = nullptr; + KReportDesignerSection *pageFooterAny = nullptr; + KReportDesignerSection *reportFooter = nullptr; + KReportDesignerSectionDetail *detail = nullptr; //Properties KPropertySet *set; @@ -193,17 +172,17 @@ QAction *itemRaiseAction; QAction *itemLowerAction; - qreal pressX; - qreal pressY; - qreal releaseX; - qreal releaseY; + qreal pressX = -1; + qreal pressY = -1; + qreal releaseX = -1; + qreal releaseY = -1; - bool modified; // true if this document has been modified, false otherwise + bool modified = false; // true if this document has been modified, false otherwise QString originalInterpreter; //Value of the script interpreter at load time QString originalScript; //Value of the script at load time - KReportData *kordata; + KReportData *kordata = nullptr; }; KReportDesigner::KReportDesigner(QWidget * parent) @@ -1172,13 +1151,15 @@ //kreportDebug() << type; KReportDesignerItemBase *ent = item->clone(); KReportItemBase *new_obj = dynamic_cast(ent); - new_obj->setEntityName(suggestEntityName(type)); - if (activeItem) { - new_obj->setPosition(KReportItemBase::positionFromScene(QPointF(activeItem->x() + 10, activeItem->y() + 10))); - } else { - new_obj->setPosition(KReportItemBase::positionFromScene(QPointF(0, 0))); + if (new_obj) { + new_obj->setEntityName(suggestEntityName(type)); + if (activeItem) { + new_obj->setPosition(KReportItemBase::positionFromScene(QPointF(activeItem->x() + 10, activeItem->y() + 10))); + } else { + new_obj->setPosition(KReportItemBase::positionFromScene(QPointF(0, 0))); + } + changeSet(new_obj->propertySet()); } - changeSet(new_obj->propertySet()); QGraphicsItem *pasted_ent = dynamic_cast(ent); if (pasted_ent) { pasted_ent->setSelected(true); diff --git a/src/wrtembed/KReportDesignerItemLine.cpp b/src/wrtembed/KReportDesignerItemLine.cpp --- a/src/wrtembed/KReportDesignerItemLine.cpp +++ b/src/wrtembed/KReportDesignerItemLine.cpp @@ -170,7 +170,12 @@ int x; int y; - QPointF p = dynamic_cast(scene())->gridPoint(event->scenePos()); + KReportDesignerSectionScene *section = qobject_cast(scene()); + if (!section) { + return; + } + + QPointF p = section->gridPoint(event->scenePos()); //kreportDebug() << p; x = p.x(); y = p.y(); @@ -188,7 +193,7 @@ m_end->setValue(positionFromScene(QPointF(x,y))); break; default: - QPointF d = mapToItem(this, dynamic_cast(scene())->gridPoint(event->scenePos())) - mapToItem(this, dynamic_cast(scene())->gridPoint(event->lastScenePos())); + QPointF d = mapToItem(this, section->gridPoint(event->scenePos())) - mapToItem(this, section->gridPoint(event->lastScenePos())); if (((line().p1() + d).x() >= 0) && ((line().p2() + d).x() >= 0) && diff --git a/src/wrtembed/KReportDesignerItemRectBase.h b/src/wrtembed/KReportDesignerItemRectBase.h --- a/src/wrtembed/KReportDesignerItemRectBase.h +++ b/src/wrtembed/KReportDesignerItemRectBase.h @@ -51,10 +51,6 @@ protected: int m_dpiX; int m_dpiY; - qreal m_userHeight; - qreal m_userWidth; - qreal m_pressX; - qreal m_pressY; enum UpdatePropertyFlag { UpdateProperty, diff --git a/src/wrtembed/KReportDesignerItemRectBase.cpp b/src/wrtembed/KReportDesignerItemRectBase.cpp --- a/src/wrtembed/KReportDesignerItemRectBase.cpp +++ b/src/wrtembed/KReportDesignerItemRectBase.cpp @@ -32,7 +32,7 @@ Private(); ~Private(); - int grabAction; + int grabAction = 0; }; KReportDesignerItemRectBase::Private::Private() @@ -112,7 +112,12 @@ qreal w, h; - QPointF p = dynamic_cast(scene())->gridPoint(event->scenePos()); + KReportDesignerSectionScene *section = qobject_cast(scene()); + if (!section) { + return; + } + + QPointF p = section->gridPoint(event->scenePos()); w = p.x() - scenePos().x(); h = p.y() - scenePos().y(); @@ -266,42 +271,45 @@ QVariant KReportDesignerItemRectBase::itemChange(GraphicsItemChange change, const QVariant &value) { - if (change == ItemPositionChange && scene()) { - QPointF newPos = value.toPointF(); - - newPos = dynamic_cast(scene())->gridPoint(newPos); - if (newPos.x() < 0) - newPos.setX(0); - else if (newPos.x() > (scene()->width() - rect().width())) - newPos.setX(scene()->width() - rect().width()); - - if (newPos.y() < 0) - newPos.setY(0); - else if (newPos.y() > (scene()->height() - rect().height())) - newPos.setY(scene()->height() - rect().height()); - - return newPos; - } else if (change == ItemPositionHasChanged && scene()) { - item()->setPosition(KReportItemBase::positionFromScene(value.toPointF())); - //TODO dont update property - //m_ppos->setScenePos(value.toPointF(), KReportPosition::DontUpdateProperty); - } else if (change == ItemSceneHasChanged && scene() && item()) { - QPointF newPos = pos(); - - newPos = dynamic_cast(scene())->gridPoint(newPos); - if (newPos.x() < 0) - newPos.setX(0); - else if (newPos.x() > (scene()->width() - rect().width())) - newPos.setX(scene()->width() - rect().width()); - - if (newPos.y() < 0) - newPos.setY(0); - else if (newPos.y() > (scene()->height() - rect().height())) - newPos.setY(scene()->height() - rect().height()); - - setSceneRect(newPos, KReportItemBase::sceneSize(item()->size()), KReportDesignerItemRectBase::DontUpdateProperty); + KReportDesignerSectionScene *section = qobject_cast(scene()); + if (section) { + + if (change == ItemPositionChange) { + QPointF newPos = value.toPointF(); + + newPos = section->gridPoint(newPos); + if (newPos.x() < 0) + newPos.setX(0); + else if (newPos.x() > (scene()->width() - rect().width())) + newPos.setX(scene()->width() - rect().width()); + + if (newPos.y() < 0) + newPos.setY(0); + else if (newPos.y() > (scene()->height() - rect().height())) + newPos.setY(scene()->height() - rect().height()); + + return newPos; + } else if (change == ItemPositionHasChanged) { + item()->setPosition(KReportItemBase::positionFromScene(value.toPointF())); + //TODO dont update property + //m_ppos->setScenePos(value.toPointF(), KReportPosition::DontUpdateProperty); + } else if (change == ItemSceneHasChanged && item()) { + QPointF newPos = pos(); + + newPos = section->gridPoint(newPos); + if (newPos.x() < 0) + newPos.setX(0); + else if (newPos.x() > (scene()->width() - rect().width())) + newPos.setX(scene()->width() - rect().width()); + + if (newPos.y() < 0) + newPos.setY(0); + else if (newPos.y() > (scene()->height() - rect().height())) + newPos.setY(scene()->height() - rect().height()); + + setSceneRect(newPos, KReportItemBase::sceneSize(item()->size()), KReportDesignerItemRectBase::DontUpdateProperty); + } } - return QGraphicsItem::itemChange(change, value); } diff --git a/src/wrtembed/KReportDesignerSection.cpp b/src/wrtembed/KReportDesignerSection.cpp --- a/src/wrtembed/KReportDesignerSection.cpp +++ b/src/wrtembed/KReportDesignerSection.cpp @@ -389,30 +389,31 @@ void KReportDesignerSectionTitle::paintEvent(QPaintEvent * event) { QPainter painter(this); - KReportDesignerSection* _section = dynamic_cast(parent()); - - const bool current = _section->d->scene == _section->d->reportDesigner->activeScene(); - QPalette::ColorGroup cg = QPalette::Inactive; - QWidget *activeWindow = QApplication::activeWindow(); - if (activeWindow) { - QWidget *par = activeWindow->focusWidget(); - if (qobject_cast(par)) { - par = par->parentWidget(); // we're close, pick common parent + KReportDesignerSection* section = dynamic_cast(parent()); + if (section) { + const bool current = section->d->scene == section->d->reportDesigner->activeScene(); + QPalette::ColorGroup cg = QPalette::Inactive; + QWidget *activeWindow = QApplication::activeWindow(); + if (activeWindow) { + QWidget *par = activeWindow->focusWidget(); + if (qobject_cast(par)) { + par = par->parentWidget(); // we're close, pick common parent + } + if (hasParent(par, this)) { + cg = QPalette::Active; + } } - if (hasParent(par, this)) { - cg = QPalette::Active; + if (current) { + painter.fillRect(rect(), palette().brush(cg, QPalette::Highlight)); } - } - if (current) { - painter.fillRect(rect(), palette().brush(cg, QPalette::Highlight)); - } - painter.setPen(palette().color(cg, current ? QPalette::HighlightedText : QPalette::WindowText)); - QPixmap pixmap(QIcon::fromTheme(QLatin1String("arrow-down")).pixmap(16,16)); - replaceColors(&pixmap, painter.pen().color()); - const int left = 25; - painter.drawPixmap(QPoint(left, (height() - pixmap.height()) / 2), pixmap); + painter.setPen(palette().color(cg, current ? QPalette::HighlightedText : QPalette::WindowText)); + QPixmap pixmap(QIcon::fromTheme(QLatin1String("arrow-down")).pixmap(16,16)); + replaceColors(&pixmap, painter.pen().color()); + const int left = 25; + painter.drawPixmap(QPoint(left, (height() - pixmap.height()) / 2), pixmap); - painter.drawText(rect().adjusted(left + pixmap.width() + 4, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, text()); + painter.drawText(rect().adjusted(left + pixmap.width() + 4, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, text()); + } QFrame::paintEvent(event); } diff --git a/src/wrtembed/KReportDesignerSectionDetail.cpp b/src/wrtembed/KReportDesignerSectionDetail.cpp --- a/src/wrtembed/KReportDesignerSectionDetail.cpp +++ b/src/wrtembed/KReportDesignerSectionDetail.cpp @@ -29,23 +29,18 @@ class Q_DECL_HIDDEN KReportDesignerSectionDetail::Private { public: - explicit Private() - : pageBreak(KReportDesignerSectionDetail::BreakNone) - {} + explicit Private() {} ~Private() { } QString name; KReportDesignerSection *detail; KReportDesigner *reportDesigner; - QList groupList; - QVBoxLayout *vboxlayout; - - int pageBreak; + int pageBreak = KReportDesignerSectionDetail::BreakNone; }; KReportDesignerSectionDetail::KReportDesignerSectionDetail(KReportDesigner * rptdes) diff --git a/src/wrtembed/KReportDesignerSectionDetailGroup.cpp b/src/wrtembed/KReportDesignerSectionDetailGroup.cpp --- a/src/wrtembed/KReportDesignerSectionDetailGroup.cpp +++ b/src/wrtembed/KReportDesignerSectionDetailGroup.cpp @@ -29,30 +29,22 @@ class Q_DECL_HIDDEN KReportDesignerSectionDetailGroup::Private { public: - explicit Private() - : groupHeader(0) - , groupFooter(0) - , pageBreak(KReportDesignerSectionDetailGroup::BreakNone) - , sort(Qt::AscendingOrder) - {} + explicit Private() {} ~Private() { - // I delete these here so that there are no widgets + //Delete these here so that there are no widgets //left floating around delete groupHeader; delete groupFooter; } QString column; - KReportDesignerSection *groupHeader; KReportDesignerSection *groupFooter; - KReportDesignerSectionDetail * reportSectionDetail; - - PageBreak pageBreak; - Qt::SortOrder sort; + PageBreak pageBreak = KReportDesignerSectionDetailGroup::BreakNone; + Qt::SortOrder sort = Qt::AscendingOrder; }; KReportDesignerSectionDetailGroup::KReportDesignerSectionDetailGroup(const QString & column, KReportDesignerSectionDetail * rsd, diff --git a/src/wrtembed/KReportDesignerSectionScene.h b/src/wrtembed/KReportDesignerSectionScene.h --- a/src/wrtembed/KReportDesignerSectionScene.h +++ b/src/wrtembed/KReportDesignerSectionScene.h @@ -70,11 +70,10 @@ KReportDesigner * m_rd; KReportUnit m_unit; - int m_minorSteps; - qreal m_majorX; - qreal m_majorY; - qreal m_pixelIncrementX; - qreal m_pixelIncrementY; + qreal m_majorX = 0.0; + qreal m_majorY = 0.0; + qreal m_pixelIncrementX = 0.0; + qreal m_pixelIncrementY = 0.0; int m_dpiX; int m_dpiY; }; diff --git a/src/wrtembed/KReportDesignerSectionScene.cpp b/src/wrtembed/KReportDesignerSectionScene.cpp --- a/src/wrtembed/KReportDesignerSectionScene.cpp +++ b/src/wrtembed/KReportDesignerSectionScene.cpp @@ -29,10 +29,8 @@ #include KReportDesignerSectionScene::KReportDesignerSectionScene(qreal w, qreal h, KReportDesigner *rd) - : QGraphicsScene(0, 0, w, h, rd) + : QGraphicsScene(0, 0, w, h, rd), m_rd(rd) { - m_rd = rd; - m_minorSteps = 0; m_dpiX = KReportPrivate::dpiX(); m_dpiY = KReportPrivate::dpiY(); @@ -80,9 +78,9 @@ } } - m_minorSteps = m_rd->propertySet()->property("grid-divisions").value().toInt(); - m_pixelIncrementX = (m_majorX / m_minorSteps); - m_pixelIncrementY = (m_majorY / m_minorSteps); + int minorSteps = m_rd->propertySet()->property("grid-divisions").value().toInt(); + m_pixelIncrementX = (m_majorX / minorSteps); + m_pixelIncrementY = (m_majorY / minorSteps); QPen pen = painter->pen(); painter->setPen(Qt::lightGray); @@ -98,7 +96,7 @@ for (int i = 0; i < wpoints; ++i) { for (int j = 0; j < hpoints; ++j) { //if (clip.contains(i * pixel_incrementx, j * pixel_incrementy)){ - if (i % m_minorSteps == 0 && j % m_minorSteps == 0) { + if (i % minorSteps == 0 && j % minorSteps == 0) { lines << QLine(QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY), QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY + m_majorX)); //painter->drawLine(); lines << QLine(QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY), QPoint(i * m_pixelIncrementX + m_majorY, j * m_pixelIncrementY)); @@ -172,9 +170,9 @@ } } - m_minorSteps = m_rd->propertySet()->property("grid-divisions").value().toInt(); - m_pixelIncrementX = (m_majorX / m_minorSteps); - m_pixelIncrementY = (m_majorY / m_minorSteps); + int minorSteps = m_rd->propertySet()->property("grid-divisions").value().toInt(); + m_pixelIncrementX = (m_majorX / minorSteps); + m_pixelIncrementY = (m_majorY / minorSteps); return QPointF(qRound((p.x() / m_pixelIncrementX)) * m_pixelIncrementX, qRound((p.y() / m_pixelIncrementY)) * m_pixelIncrementY); }